【问题标题】:Error in Ops.factor(host_neighbourhood, neighbourhood) : level sets of factors are differentOps.factor(host_neighbourhood, neighbourhood) 中的错误:因子的水平集不同
【发布时间】:2019-07-27 18:11:06
【问题描述】:

我试图比较变量列中的两个值,看看有多少匹配,有多少不同。但是,它向我发送了这个错误,我不确定在哪里解决问题。

我使用了管道功能并尝试了filter()内部和外部的过滤功能,但这似乎并不重要。

same_nbh <- seattle_airbnb %>% filter(host_neighbourhood == neighbourhood)

我收到此错误:

Ops.factor(host_neighbourhood, neighbourhood) 中的错误:因子的级别集不同

【问题讨论】:

    标签: r dataframe


    【解决方案1】:

    来自?factor

    一个因素只能与具有相同水平集的另一个因素进行比较(不能 必须以相同的顺序)或字符向量。

    因此您需要将变量转换回字符(或首先阻止它们变成因子),例如

    (seattle_airbnb 
       %>% mutate_at(c("host_neighbourhood","neighbourhood"), as.character)
       %>% filter(host_neighbourhood == neighbourhood)
    )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-11-08
      • 1970-01-01
      • 1970-01-01
      • 2020-11-13
      • 2016-06-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多