Last active
January 15, 2021 11:33
-
-
Save simonthompson99/38d77ee66fbdb1463419d43071e685be to your computer and use it in GitHub Desktop.
[Concatenate flag columns] Concatenate flag columns into a single column #r
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # take a load of boolean flag columns (names beginning with f_) and produce a column that lists which flags the row is true for | |
| concat_flags <- function(x){ | |
| separator = ';' | |
| a <- paste0(names(x)[as.logical(x)], sep = separator) | |
| ifelse(a == separator, NA, a) | |
| } | |
| data$concat_flags <- apply(data[,colnames(data)[startsWith(colnames(data), "f_")]], 1, concat_flags) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment