无法使用 Dplyr 和 distinct() 过滤不同的行:“distinct_”没有适用的方法应用于“factor”类的对象

Cod*_*nto 1 r dplyr

我正在尝试使用 dplyr 过滤数据框中列的不同值,但我不断收到“评估错误:没有适用于 'distinct_' 的方法应用于“因子”类的对象。

我尝试将我尝试过滤的列的类更改为字符和因子,但两者都会导致错误。

例子:

testFrame<-c("a","b","c","c"))
testFrame<-as.data.frame(testFrame)
testFrame %>% filter(distinct(testFrame, .keep_all=TRUE))
#Results in Error in filter_impl(.data, quo) :
#Evaluation error: no applicable method for 'distinct_' applied to an object of class "factor".

Run Code Online (Sandbox Code Playgroud)

这应该从我的数据库中删除第四行,只留下 a,b,c 的值

Cod*_*nto 5

找出我自己问题的答案,在我不可避免地再次忘记时将其张贴在这里:

您不能使用带有 distinct 的过滤器,您只需要使用 distinct。因此,代码变为:

testFrame<-c("a","b","c","c"))
testFrame<-as.data.frame(testFrame)
testFrame %>% distinct(testFrame, .keep_all=TRUE)
Run Code Online (Sandbox Code Playgroud)

然后它返回 a,b,c 的期望值