简体   繁体   English

从数据框中的索引请求中删除列

[英]Removing columns from an index request in a data frame

Hi I currently have the code: 嗨,我目前有代码:

matrixed.data <- data.matrix(df[1:row.dim,7:col.dim])

Where the row.dim and col.dim are variables for the size of the whole frame. 其中row.dim和col.dim是整个帧大小的变量。 I would like to remove the column "df$WEATHER" that is included in the col.dim selection but don't know how to word it. 我想删除col.dim选择中包含的“ df $ WEATHER”列,但不知道该怎么写。 I have tried adding - df$WEATHER and !df$WEATHER inside the bracket but fear I'm misinterpreting the scope of these commands. 我曾尝试在括号内添加-df $ WEATHER和!df $ WEATHER,但担心我误解了这些命令的范围。

Is it possible to do this without creating a new col.dim variable; 是否可以在不创建新的col.dim变量的情况下执行此操作? I'm trying to keep the code as limitless as possible as the data frame may increase in size in the future. 我试图使代码尽可能地不受限制,因为将来数据帧的大小可能会增加。

Thank you digEmAll! 谢谢digEmAll! I thought it would be reasonably simple I'm just a bit too green at R to think of something like that. 我以为这很简单,我对R有点绿,无法想到这样的东西。 For others what worked for me was: 对于其他人,对我有用的是:

(df[1:row.dim, setdiff(7:col.dim,which(names(df) == "WEATHER"))])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM