Skip to content

Instantly share code, notes, and snippets.

@czeildi
Created June 25, 2017 11:05
Show Gist options
  • Save czeildi/b71d76f9ec66c02771514bacb8403493 to your computer and use it in GitHub Desktop.
Save czeildi/b71d76f9ec66c02771514bacb8403493 to your computer and use it in GitHub Desktop.
define new column from list of columns in data.table rowwise
# 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