-2

I have very little experience in R. Thanks in advance for any assistance. Please point to any previous posts if already answered. I have a table with column headers of : ID Param Result for each id I could have up to 15 params & results, including NA. How do I count the number of results excluding blank or NAs by ID? nrow seems to give me the total number of results for each table, I need it broken down to count per id.

1 Answers1

0

Lets say your table is called mytable.

OPTION 1: na.omit() removes any rows that have any NA within them

mytable = na.omit(mytable)
nrow(mytable)

OPTION 2: use the is.na() function. This returns a logical value (TRUE) if the value is NA. By putting the "!", we get the opposite (FALSE). Length will return the number of values of interest. In this case that would be non-NA values.

length(!is.na(mytable$ID))
kpr62
  • 522
  • 1
  • 4
  • 11