【发布时间】:2021-10-11 14:39:39
【问题描述】:
我正在尝试在数据框中查找多个名称。下面的示例“名称”将是 df。我很好奇为什么我不能得到整个集合的唯一数据。
unique(Names[1:3])
#Names is the df they are in, this has been giving me a table with all the names
unique(Names$colname)
#Has been working but this method won't filter out unique names for each column bc its diff commands
【问题讨论】:
-
您好,欢迎您!将来,请使用
dput()提供可重现的数据样本,如Names。就目前而言,您需要获取Names数据框,它实际上是向量(列)的(命名)list,并且在使用unique()之前unlist()它:@ 987654329@。这会将所有目标数据合并到一个向量中,unique()现在可以在该向量上进行操作。 -
@Greg 所以本质上,我需要将它从 df bc unique() 中取出,它不会为此工作,它需要一个向量。抱歉,我尝试使用三个刻度线,但我认为结果不正确。
-
我的建议对你有用吗?即
unique(unlist(Names[1:3])),或使用R 4.1 或更高版本中可用的本机|>管道:Names[1:3] |> unlist() |> unique()