Created
June 25, 2017 11:05
-
-
Save czeildi/b71d76f9ec66c02771514bacb8403493 to your computer and use it in GitHub Desktop.
define new column from list of columns in data.table rowwise
This file contains 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
# dt is a data.table with id_cols and value_cols | |
# we want rows where any of the value cols is not NA regardless of the | |
# values of the id_cols | |
dt[, to_keep := purrr::pmap_lgl( | |
purrr::map_df( | |
dt[, .SD, .SDcols = value_cols], | |
~ !is.na(.x) | |
), | |
any | |
)] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment