Reputation: 735
I have this code that works fine:
CompleteCoxObs<-temp[is.na(temp[,8])== FALSE | is.na(temp[,9])== FALSE | is.na(temp[,10])== FALSE,];
What is a better and more efficient way to achieve the same result?
Upvotes: 1
Views: 6117
Reputation: 11
temp[apply(!is.na(temp[,8:10]),1,any),]
Note placing the "!" in front of is.na
Upvotes: 1
Reputation: 7720
You can try one of the followings:
temp[!is.na(rowSums(temp[,8:10])),]
or
temp[!apply(is.na(temp[,8:10]),1,any),]
or
temp[na.omit(temp[,8:10]),]
Upvotes: 2
Reputation: 28826
You can try this to check for all the columns:
CompleteCox.df <- temp.df[rowSums(is.na(temp.df)) != ncol(temp.df),]
In your case:
CompleteCox.df <- temp.df[rowSums(is.na(temp.df[, c(8,9,10)])) != 3,]
Upvotes: 4