Right now I'm trying to summerize my rows, but keep all the values except the unique_id. Here is my current code:
library(dplyr)
rm_na_unique <- function(vec){
unique(vec[!is.na(vec)])
}
trial <- test1 %>%
group_by(unique_id) %>%
summarise_each(funs(toString(rm_na_unique(.))))
This removes duplicates, but how would I change the last part: summarise_each(funs(toString(rm_na_unique(.)))) to keep all values (whether it's all the same value) in my cell? Thank you.
Starting DF
Unique_id Name State
1 Rich PA
1 Rich PA
1 Rich PA
2 Tim DE
2 Tim DE
2 Tim DE
Desired Result
Unique_id Name state
1 Rich,Rich,Rich PA,PA,PA
2 Tim,Tim,Tim DE,DE,DE
Based on a previous questions, I can see that I can accomplish this using the following code:
library(dplyr)
df %>%
group_by(unique_id) %>%
summarise(name=paste(name,collapse=','))
But how would I apply this to the entire data frame and not just one or two variables?