Re: [R] data-management: Rowwise NA

From: moleps <moleps2_at_gmail.com>
Date: Thu, 03 Jun 2010 21:39:28 +0200

-Any- was my fix... Appreciate it.

//M

On 3. juni 2010, at 21.33, Phil Spector wrote:

> ?any
> 
> Not really a reproducible answer, but I think you're looking
> for
> 
> apply(tes[,sam],1,function(x)any(is.na(x)))
> 
> 
> 					- Phil Spector
> 					 Statistical Computing Facility
> 					 Department of Statistics
> 					 UC Berkeley
> 					 spector_at_stat.berkeley.edu
> 
> 
> On Thu, 3 Jun 2010, 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_at_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. Received on Thu 03 Jun 2010 - 20:07:15 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 03 Jun 2010 - 21:00:27 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive