0

I would like to find out how many entries each column has? I have over 1000 columns of data, whilst some contain NA.

For example:

Date  A   B
1990  NA  NA
1991  1   NA
1992  2   2
1993  3   3
1994  4   NA
1995  5   3
1996  NA  NA
1997  7   8
1998  8   2
1999  NA  NA
2000  8   4

Below is the result I would like.

A   B  
8   6

Many Thanks

kg23
  • 51
  • 5

1 Answers1

1

You can try

colSums(Negate(is.na)(df))

or

lengths(Map(na.omit,df))

which gives

Date    A    B 
  11    8    6
ThomasIsCoding
  • 96,636
  • 9
  • 24
  • 81