Advertisement
Guest User

Untitled

a guest
Mar 18th, 2019
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. library(data.table)
  2. mother_dt <- data.table(mother = c("Penny", "Penny", "Anya", "Sam", "Sam", "Sam"),
  3. child = c("Violet", "Prudence", "Erika", "Jake", "Wolf", "Red"))
  4. mother_dt [, children := .(list(unique(child))), by = mother]
  5. mother_dt [, child := NULL]
  6. mother_dt <- unique(mother_dt , by = "mother")
  7.  
  8. child_dt <- data.table(child = c("Violet", "Prudence", "Erika", "Jake", "Wolf", "Red"),
  9. age = c(10, 8, 9, 6, 5, 2))
  10.  
  11. combined_dt <- mother_dt[, child_age := ifelse(child_dt$child %in% children,
  12. .(list(unique(child_dt$age))), NA)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement