[R] if + is.na
Ben Bolker
bolker at ufl.edu
Sun Jun 14 22:27:03 CEST 2009
Grześ wrote:
>
> Hello!
> I wont to use a function is.na()
>
> I have two vectors:
>> a=c(1,NA,3,3,3)
>> b=c(0,0,0,0,0)
> and when I use is.na function it's ok:
>> is.na(a)
> [1] FALSE TRUE FALSE FALSE FALSE
>
> but I would create sth like this:
>
> for i in 1:length(a){
> if (wsp[i] == is.na(a)) {b=43}
> }
> or like this
>
> if(is.na(a)) b=3 else a
> [1] 1 NA 3 3 3
>
> but I always get an error:
> the condition has length > 1 and only the first element will be used
>
> Could you help me how I may avoid this problem and use function is.na
> inside function if - else
>
>
Use "ifelse" instead of "if"
--
View this message in context: http://www.nabble.com/if-%2B-is.na-tp24025136p24025414.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list