2
我有以下data.table
:子data.table列通過列表匹配
dt1 <- data.table(apple = c(1:5),
bananas = c(5:1),
carrots = c(6:10),
donuts = c(11:15))
及以下list
:
names_to_keep <- c("apple", "carrots")
我需要創建dt1
只包括一個新的data.table
列入名字的列表包含在names_to_keep
中。
期望的結果:
# apple carrots
#1: 1 6
#2: 2 7
#3: 3 8
#4: 4 9
#5: 5 10