Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(data.table)
- mother_dt <- data.table(mother = c("Penny", "Penny", "Anya", "Sam", "Sam", "Sam"),
- child = c("Violet", "Prudence", "Erika", "Jake", "Wolf", "Red"))
- mother_dt [, children := .(list(unique(child))), by = mother]
- mother_dt [, child := NULL]
- mother_dt <- unique(mother_dt , by = "mother")
- child_dt <- data.table(child = c("Violet", "Prudence", "Erika", "Jake", "Wolf", "Red"),
- age = c(10, 8, 9, 6, 5, 2))
- combined_dt <- mother_dt[, child_age := ifelse(child_dt$child %in% children,
- .(list(unique(child_dt$age))), NA)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement