I have a number of columns that I would like to remove from a data frame.
(我想从数据框中删除许多列。)
I know that we can delete them individually using something like:(我知道我们可以使用类似的方法分别删除它们:)
df$x <- NULL
But I was hoping to do this with fewer commands.
(但是我希望用更少的命令来做到这一点。)
Also, I know that I could drop columns using integer indexing like this:
(另外,我知道我可以使用整数索引删除列,如下所示:)
df <- df[ -c(1, 3:6, 12) ]
But I am concerned that the relative position of my variables may change.
(但是我担心我的变量的相对位置可能会改变。)
Given how powerful R is, I figured there might be a better way than dropping each column one by one.
(考虑到R的强大功能,我认为可能有比逐一删除每一列更好的方法。)
ask by Btibert3 translate from so