【发布时间】:2020-11-20 00:57:38
【问题描述】:
我的数据框中有一个分类列,其中包含 14 种不同的字符串可能性。我想创建一个只保留 3s 字符串并将所有剩余字符串折叠为“其他”的新变量。
我想通过首先创建一个向量来执行此操作,该向量具有出现 3 个类别之一的行号,然后将它们组合起来:
x <- which(binarydata1$Sector=="Independent artist")
y <- which(binarydata1$Sector=="Arts and Culture")
z <- which(binarydata1$Sector=="Community or Social Services")
object <- c(x, y, z) #This contains all the row values of the strings listed, the ones I don't want to change ....
我可以用它来调用列中不等于这些值的行值,以便我可以用其他替换这些字符串吗?还是我认为这一切都错了?
【问题讨论】:
-
请发布有代表性的数据以供使用。您可以对包含您感兴趣的
Sector值的数据子集使用dput(bindarydata1)或dput来执行此操作。请参阅minimal reproducible example。