[R] ifelse()
Sarah Goslee
sarah.goslee at gmail.com
Tue Feb 10 23:08:53 CET 2009
Did you read the helpfile?
If your condition is true, the first option is returned. If it is false, the
second option is returned.
For the first four elements of X, all of which are greater than zero,
1 is returned. For the last two, which are not greater than zero,
0 is returned.
Sarah
On Tue, Feb 10, 2009 at 4:44 PM, kayj <kjaja27 at yahoo.com> wrote:
>
> 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
>
--
Sarah Goslee
http://www.functionaldiversity.org
More information about the R-help
mailing list