Hi there,

One option would be

apply(tes, 1, function(.row) any(is.na(.row[c(1,3)])))

See ?any, ?is.na and ?apply for more information.

HTH,
Jorge


On Thu, Jun 3, 2010 at 3:20 PM, moleps <> wrote:

> Dear R´ers..
>
> In this mock dataset how can I generate a logical variable based on whether
> just tes or tes3 are NA in each row??
>
> test<-sample(c("A",NA,"B"),100,replace=T)
> test2<-sample(c("A",NA,"B"),100,replace=T)
> test3<-sample(c("A",NA,"B"),100,replace=T)
>
> tes<-cbind(test,test2,test3)
>
> sam<-c("test","test3")
> apply(subset(tes,select=sam),1,FUN=function(x) is.na(x))
>
> However this just tests whether each variable is missing or not per row.
> I´d like an -or- function in here that would provide one true/false per row
> based on whether test or tes3 are NA. I guess it would be easy to do it by
> subsetting in the example but I figure there is a more elegant way of doing
> it when -sam- contains 50 variables...
>
> //M
>
>
>
>        [[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.
>
>

        [[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