R语言如何去除重复的单词例如:
cropRotation = c("canola", "soybeans", "soybeans", "wheat", "canola", "wheat", "canola", "soybeans", "canola", "wheat", "canola", "soybeans", "canola", "soybeans", "wheat", "canola",
"soybeans", "canola","wheat", "canola","wheat", "soybeans","soybeans", "wheat", "soybeans", "canola", "soybeans", "canola")
如何只剩下("canola","soybeans","wheat")
请给出代码示例,谢谢!
cropRotation %>% distinct()
R语言可用unique命令进行去重:
unique可返回一个把重复元素或行给删除的向量、数据框或数组
x = c(1, 2, 2, 3, 3, 3)
unique(x)
1 2 3
类似的,使用unique(cropRotation)即可达到去重的目的~