Need help with R

Thanks for helping me with R's ifelse.

This creates a fake dataset.
test = expand.grid(a = c(1, 2, 3, 4), b = c(1, 2, 3))

What I want to do is to something like this:

if a=3 then do;

if b=1 then news="3 and 1";

if b=2 then news="3 and 2";

end;

 

This below does half of the job.  Could you advise?

test$news <- ifelse(test$a == 3,ifelse(test$b == 1, "3 and 1",""),"")

Please email me at k u e k a w a @gmail.com .

Thanks.

CategoriesR

Leave a Reply