Hi,
I have this simple data file where I would like to add count (to existing sum and mean) and total of Gender at the top or bottom of the table.
I also have issues with ends_with which should contain both "len" and "count". If this worked I would need just one table.
URN <- c("aaa", "bbb", "ccc", "ddd", "eee", "fff", "ggg", "hhh", "iii", "jjj", "kkk", "lll", "mmm", "nnn", "ooo", "ppp")
A_len <- c(20, 0, 10, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0)
C_len <- c(0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1)
A_wcount <- c(3, 0, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1)
C_wcount <- c(0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1)
Gender <- c("Male", "Male", "Male", "Male", "Male", "Male", "Female", "Female", "Female", "Female", "Female", "Female", "Male", "Male", "Male", "Male")
response.data <- data.frame(URN, A_len, C_len, A_wcount, C_wcount, Gender)
l.result <- response.data %>%
select(Gender, ends_with("len")) %>%
group_by(Gender) %>%
summarise_all(list(Aver = mean, Sum = sum))
c.result <- response.data %>%
select(Gender, ends_with("count")) %>%
group_by(Gender) %>%
summarise_all(list(Aver = mean, Sum = sum))
I do apologize if the question is too basic but I cannot find a solution in dplyr documentation...