【问题标题】:How to subset a data frame with R pipeline如何使用 R 管道对数据框进行子集化
【发布时间】:2020-12-16 11:20:02
【问题描述】:

我正在尝试根据来自另一个数据帧的相应列元素对数据帧进行子集化/过滤。 这是我以前这样做的

df <- df1[df1$col1 %in% df2$col2,]

然后我要将列设置为行名

df <- df %>% remove_rownames %>% column_to_rownames('col1')

但是我不知道如何使用%&gt;% 将这两个代码合并为一个

【问题讨论】:

  • 第一次操作使用过滤器

标签: r tidyverse pipeline


【解决方案1】:
df1 %>% filter(col1 %in% df2$col2) %>% remove_rownames %>% column_to_rownames('col1')

【讨论】:

    猜你喜欢
    • 2014-11-13
    • 2021-12-04
    • 1970-01-01
    • 1970-01-01
    • 2021-02-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多