0

I would like to remove all the columns from my data frame that contain less than 3 entries.

Here is an example of the result I would like:

A  B  C  D
NA NA NA 1
NA NA 1  2
NA NA 2  3
NA 6  3  4
3  5  4  NA
C  D
NA 1
1  2
2  3
3  4
4  NA

I have a dataframe of over 1000 columns, how would I do this for the whole set?

Many Thanks

kg23
  • 51
  • 5

1 Answers1

1

You can try the code below

subset(df,select = colSums(!is.na(df))>=3)

which gives

   C  D
1 NA  1
2  1  2
3  2  3
4  3  4
5  4 NA
ThomasIsCoding
  • 96,636
  • 9
  • 24
  • 81