0

How can I subset column a and b using column1 and column2 character vectors? Example below

library(data.table)

df <- data.table(a = c(1, 2, NA, 3), b = c(6:9))
column1 <- 'a'
column2 <- 'b'

df[is.na(column1), column2, with = F]

# Desired output

df[is.na(a), .(b)]
MLEN
  • 2,162
  • 2
  • 20
  • 36
  • You can do it with: `df[is.na(get(column1)), ..column2]`. The linked answer requires an updated answer I guess. – mt1022 Sep 01 '18 at 08:20
  • this works for me, but im not sure if it uses the full data.table power this way: df[is.na(df[[column1]]), ..column2,]. – TinglTanglBob Sep 01 '18 at 08:22

0 Answers0