I have a dataframe that looks like this:
Community, Sex, Total Pop, Age, Median
Kodiak,F,NA,NA,3
Kodiak,F,4,Na,NA
Kodiak,F,NA,5,NA
Teru,F,NA,0,NA
Teru,F,0,NA,NA
I would like to collapse all of the rows with the common community value name. However, I would also like to keep the NAs (I've done this awhile ago and it made the NAs into 0s which is confusing since 0 has value - the data is census data). My actual dataframe has thousands of rows.
I've tried:
library(data.table)
fcensus7 <- fcensus6 %>%
group_by(Community) %>%
summarise_each(funs(sum(., na.rm = TRUE)))
But end up getting this error (it worked before but also made all my NA's into zeroes):
Error in summarise_impl(.data, dots) : invalid 'type' (character) of argument