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)]
2
  • You can do it with: df[is.na(get(column1)), ..column2]. The linked answer requires an updated answer I guess. Commented Sep 1, 2018 at 8: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,]. Commented Sep 1, 2018 at 8:22

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.