I am grouping data and then summarizing it, but would also like to retain another column. I do not need to do any evaluations of that column's content as it will always be the same as the group_by column. I can add it to the group_by statement but that does not seem "right". I want to retain State.Full.Name
after grouping by State
. Thanks
TDAAtest <- data.frame(State=sample(state.abb,1000,replace=TRUE))
TDAAtest$State.Full.Name <- state.name[match(TDAAtest$State,state.abb)]
TDAA.states <- TDAAtest %>%
filter(!is.na(State)) %>%
group_by(State) %>%
summarize(n=n()) %>%
ungroup() %>%
arrange(State)
summarise
? Based on the code, you are doing it by both the columns – akrunsummarize(State.Full.Name = unique(State.Full.Name), n=n())
, which is less concise. – alistairecount(...)
is equivalent togroup_by(...) %>% summarise(n = n())
– alistaire