Consider
if(sample(2, 1) == 1) a <- 5 else b <- 5
This is repetitive. Is there any way to not have to write <- 5
twice?
CodePudding user response:
You may use assign
-
assign(if(sample(2, 1) == 1) 'a' else 'b', 5)
Consider
if(sample(2, 1) == 1) a <- 5 else b <- 5
This is repetitive. Is there any way to not have to write <- 5
twice?
CodePudding user response:
You may use assign
-
assign(if(sample(2, 1) == 1) 'a' else 'b', 5)