【问题标题】:How can I apply the filter() function to select variable values?如何应用 filter() 函数来选择变量值?
【发布时间】:2021-09-26 09:50:39
【问题描述】:

我正在寻找有关应用 filter() 函数的一些指导。

以下是我的数据示例,我想过滤掉“治疗”年份为 2006、2007 和 2008 年的投资者。

数据示例如下:

investor dealyear dealcounts treatment other characteristics
123 IM 2003 5 2006 various
123 IM 2004 5 2006 various
123 IM 2005 5 2006 various
123 IM 2006 5 2006 various
123 IM 2007 5 2006 various
21 Invest 2002 5 2008 various
21 Invest 2003 5 2008 various
21 Invest 2004 5 2008 various
21 Invest 2005 5 2008 various
21 Invest 2006 5 2008 various
21 Invest 2007 5 2008 various
21 Invest 2008 5 2008 various

感谢您的任何提示!

【问题讨论】:

    标签: r filter tidyverse


    【解决方案1】:

    你的意思是这样的吗?

    result<- df %>% filter(!investor %in% unique(investor[treatment %in% 2006:2008]))
    

    在基础 R 中 -

    result <- subset(df, !investor %in% unique(investor[treatment %in% 2006:2008]))
    

    【讨论】:

      猜你喜欢
      • 2017-05-02
      • 1970-01-01
      • 2018-02-15
      • 2018-10-10
      • 2018-12-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-29
      相关资源
      最近更新 更多