Select rows with same columns from dataframe
I have a data frame with multiple columns. I want to select rows without NA
(like with complete.cases
) and all columns are identical. For example, for
> f <- data.frame(a=c(1,NA,NA,4),b=c(1,NA,3,40),c=c(1,NA,5,40))
> f
a b c
1 1 1 1
2 NA NA NA
3 NA 3 5
4 4 40 40
I want the vector to TRUE,FALSE,FALSE,FALSE
only select the first row because all three columns are the same and none of them are NA
.
I can do
Reduce("==",f[complete.cases(f),])
but this creates an intermediate dataframe which I would like to avoid (to save memory).
+3
source to share