'group_by combined with frq() is excluding NAs from group variables, but I want to keep them
I'm outputting summary statistics using frq() because my dataset has haven labels that I want displayed. I found that when I used group_by and run this, however, the output excludes groups with missing values. Reproducible example:
library(dplyr)
library(sjmisc)
look<-cars
look<-look %>% mutate(color=case_when(
speed > 10 ~ 'red',
TRUE ~ 'blue'
))
temp<-data.frame(speed=12,dist=12)
look<-bind_rows(look,temp)
rm(temp)
look<-look %>% group_by(color) %>% frq(speed)
look<-as.data.frame(look)
sum(look$frq)
[1] 50
Here we see that only 50 rows are summarized and the one with is.na(color) is excluded.
Is there any way to get groups with NA to show?
Thanks!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
