0

I am pretty sure it exists somehow but I cannot find the answer on SO: I want to select a subset of a data.frame by using df[-"name"] of something similar since it is possible to use df["name"] e.g. :

df <- data.frame(x = 1:5, y = 2:6, z = 3:7)
df_plane <- df[-"z"] # what I want to type
df_plane <- df[,-3] # what I want to be done

thanks

ClementWalter
  • 4,814
  • 1
  • 32
  • 54
  • `subset(df, select = -z)` works but is generally discouraged. http://stackoverflow.com/q/9860090/1191259 – Frank Nov 12 '15 at 19:57
  • 2
    Seems like a dupe of [this](http://stackoverflow.com/questions/4835342/how-can-i-get-a-dataframe-with-columns-temporarily-removed-by-name) (which also provides a nice explanation "why negative string indices does not work". [See also](http://stackoverflow.com/questions/4605206/drop-columns-in-r-data-frame) – Henrik Nov 12 '15 at 20:01
  • my mistake @Henrik you're totally right – ClementWalter Nov 12 '15 at 20:03

0 Answers0