Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
298 views
in Technique[技术] by (71.8m points)

r - how to count the total without NA

I want to do a summary count by group. And I don't want the final results include the calculation of 'NA'. I used the codes like following:

Outcome <- df %>% group_by(Subject) %>% summarise(Outcome_Count = n(),na.rm=TRUE)

But it did not exclude NA, instead it add a var na.rm. It looks like this: enter image description here

What should I do now in order to get Outcome without last row? I still want the one for UNKNOWn. It means differently compared to the case with NA.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Maybe this filtering out NA from your key variable:

#Code
Outcome <- df %>% group_by(Subject) %>%
  filter(!is.na(AEOUT)) %>%
  summarise(Outcome_Count = n())

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...