Hello,

ifelse checks condition whether X (or, ina fact every value in X) is greater
than 0. If it is 1 is assigned and if it isn't then 0.

2 and 1 are greater than 0, therefore the first four values of Y are 1. 0
isn't greater than 0, therefore the last two values of Y are 0.

2009/2/10 kayj <kjaj...@yahoo.com>

>
> I have a problem with ifelse(), I do not understand how it works.
>
> > X<-c(2,2,1,1,0,0)
> > str(X)
>  num [1:6] 2 2 1 1 0 0
> > Y<-ifelse(X>0,1,0)
> > Y
> [1] 1 1 1 1 0 0
> >
>
> Can some one explain what is going on, I do not understand what ifelse is
> doing in this case. Can someone explain the output Y.
>
> Thanks
>
> --
> View this message in context:
> http://www.nabble.com/ifelse%28%29-tp21943308p21943308.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html<http://www.r-project.org/posting-guide.html>
> and provide commented, minimal, self-contained, reproducible code.
>

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to