I have a data frame called called issuesdata
that I created from a larger frame, clean.data
issue1 <- as.vector(clean.data$issue1)
issue2 <- as.vector(clean.data$issue2)
issue3 <- as.vector(clean.data$issue3)
issuesdata <- data.frame(issue1, issue2, issue3)
issuesdata %>% dplyr::slice(10:15)
issue1 issue2 issue3
1 economic <NA> <NA>
2 economic unification <NA>
3 economic <NA> <NA>
4 transportation aviation <NA>
5 justice <NA> <NA>
6 slavery economic humanrights
I have two goals:
- Merge these columns together such that there is a fourth column containing all the issues in one character string (column name:
allissues
) - The text of the issues in
allissues
are alphabetized
For example, Row 2 of allissues
would stay in the be in the form economic unification
but be one character string. Row 4 would be Aviation Transportation
, while Row 6 is economic humanrights slavery
.
How do I go about doing this?
Rowwise drop NA values, sort them and paste them together.
In base R :
Or with
dplyr
: