Re: [R] data-management: Rowwise NA

2010-06-03 Thread moleps
-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 >

Re: [R] data-management: Rowwise NA

2010-06-03 Thread David S Freedman
you probably want to use the apply function: d=sample(1000,500); d[sample(500,50)]<-NA; #put 50 NAs into the data d=data.frame(matrix(d,ncol=50)); names(d)=paste('var',1:50,sep='.') d apply(d,1,sum) #are any of the row values NA ? apply(d,2,function(x)sum(is.na(x))) #how many values for each of

Re: [R] data-management: Rowwise NA

2010-06-03 Thread Marc Schwartz
On Jun 3, 2010, at 2: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,"

Re: [R] data-management: Rowwise NA

2010-06-03 Thread Jorge Ivan Velez
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 >

Re: [R] data-management: Rowwise NA

2010-06-03 Thread Phil Spector
?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 o

[R] data-management: Rowwise NA

2010-06-03 Thread moleps
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("t