1

I use R and run the following comands

x = c(1,2,3)
y = c(4,5,6)
s = rbinom(1,1,0.5)
ifelse(s==1,x,y)

However, when I run it instead of getting the whole vectors on each case, I just get back the first element of the vector. How do I solve that?

Jonathan1234
  • 489
  • 2
  • 9

1 Answers1

3

We may use if/else here

if(s == 1) x else y
akrun
  • 874,273
  • 37
  • 540
  • 662