Search code examples
rdataframenamissing-data

Select rows with non-NA values in at least one of the desired columns


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?


Solution

  • 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,]