R:根据列中的因子对数据框中的行进行子设置

时间:2018-09-30 17:08:06

标签: r subset

我有一个数据帧df,它由大量的行和几列组成。我想根据列x6中的内容删除一系列行(请参见下面的代码):

为此,我编写了代码:

subset(df, x6 == "1 -Energy", "2 - Industrial Processes and Product Use", "3 
- Agriculture", "4 - Land Use, Land-Use Change and Forestry", "5 - Waste 
management", "6 - Other Sector")

R不允许此命令,我想知道我需要更改什么?

感谢各种帮助。再次感谢!

Nordsee

1 个答案:

答案 0 :(得分:1)

您可能会改用此​​命令:

subset(df, x6 %in% c("1 -Energy", "2 - Industrial Processes and Product Use", "3 - Agriculture", "4 - Land Use, Land-Use Change and Forestry", "5 - Waste management", "6 - Other Sector") )

当心%in%运算符。