0

I have a dataframe of about 4000 x 50000, and I have a variable "x" which contains the name of the variables I would like to drop from the dataframe. Here's an example of what my data looks like:

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")

I am trying to do something like

> df2 <- df[,-x]
Error in -x : invalid argument to unary operator
> df2 <- df[,!x]
Error in !x : invalid argument type

But they both do not seem to work!

Frank
  • 66,179
  • 8
  • 96
  • 180
Error404
  • 6,959
  • 16
  • 45
  • 58

0 Answers0