I am a beginner in R. I have a small task to do.
I am trying to find the columns of a data frame that have less that 2 null values
The data frame I am working on in as below,
df=
a b c
1. NA NA NA
2. NA NA 10
3. NA NA 23
4. NA 60 54
5. NA 60 67
Typically I want the column (c) from the above dataframe as an output
The code I have attempted is:
na_count <- sapply(df, function(y) sum(length(which(is.na(y)))))
na_count <- data.frame(na_count)
newdf <- na_count[na_count$na_count < 2,]
Using the above code I get an output as;
[1] 1
The out put gives the count of NA in Column (c).
I understand why I am getting the above output. But can't find a way to correct it.
Any help would be appreciated.