我有一个大约 4000 x 50000 的数据框,我有一个变量“x”,其中包含我想从数据框中删除的变量的名称。这是我的数据的示例:
df <- structure(list(A = structure(1:7, .Label = c("B", "C", "D", "E",
"F", "G", "H"), class = "factor"), B = c(13, 89, 938, 89, 3,
3, 4), C = c(453, 46, 13, 64, 453, 3, 3), D = c(36, 84, 3, 34,
1, 36, 465), E = c(4, 48, 63, 53, 351, 3, 34), F = c(654, 43,
53, 46, 56, 3, 5), G = c(56, 21, 210, 543, 69, 6, 6563), H = c(112,
45, 1531, 53135, 51, 123, 12)), .Names = c("A", "B", "C", "D",
"E", "F", "G", "H"), row.names = c(NA, 7L), class = "data.frame")
x <- c("A","B","C")
我正在尝试做类似的事情
> df2 <- df[,-x]
Error in -x : invalid argument to unary operator
> df2 <- df[,!x]
Error in !x : invalid argument type
但它们似乎都不起作用!