Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why ifelse function doesn't display vector as output in R

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

We may use if/else here

if(s == 1) x else y
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading