I trying to using dplyr distinct to combine rows, delete duplicates, and delete blanks as well. Here is my data frame:
unique_id school subject grade sex
1 great Math 88
1 great English 78
1 great History 98 male
2 spring Math 65
2 spring English 72 female
2 spring History 84
When I run (thank you Akrun):
(r2 <- df %>%
group_by(unique_id) %>%
summarise_each(funs(toString(unique(.)))))
I get:
unique_id school subject grade sex
1 great Math, English, History 88,78,98 , male
2 spring English, English, History 65,72,84 , female
I don't want blanks to be included or commas in the last variable, sex. Instead, I'd like it to look as follows:
unique_id school subject grade sex
1 great Math, English, History 88,78,98 male
2 spring English, English, History 65,72,84 female
Any tried adding NA on the import, then removing it after condensing and that didn't work. Any ideas how to condense rows, but only keep the value in the row and ignore blanks? Thank you.
See Question&Answers more detail:os