我是一个R菜鸟。所以我在名为ncol(a)
的变量中有一个data.table。我试图通常获得最后一栏。它在我指定第6列时有效,但它不能与class(a)
[1] "data.table" "data.frame"
a
permissions size month date timestamp file
1: drwxr-xr-x 8192 Oct 02 14:25 to_xpn
2: drwxr-xr-x 8192 Oct 04 10:38 from_xpn
ncol(a)
[1] 6
a[,6]
file
1: to_xpn
2: from_xpn
a[,ncol(a)]
[1] 6
一起使用。那是为什么?
potatoerules <- subset(rules , items %in% "potatoe")
答案 0 :(得分:2)
您只需要with = FALSE
library(data.table)
iris.dt <- data.table(iris)
iris.dt[, ncol(iris.dt), with = FALSE]
# Species
# 1: setosa
# 2: setosa
# 3: setosa
# 4: setosa
# 5: setosa
# ---
# 146: virginica
# 147: virginica
# 148: virginica
# 149: virginica
# 150: virginica