根据字符串排列过滤行

时间:2019-08-06 07:43:59

标签: r dataframe

我有一个有点混乱的数据框,但我有一列称为分支逻辑,其中包含一些类似于公式的模式。称为分支逻辑的列如下所示:

dput(df)
df<-structure(list(column1 = c("John", "Jane", "Erick"),
                   column2 = c("J34", "J345", "Er456"),
Branching_Logic = c("Silva = '1' and Silva = '2' ", "Mary = '2' or Mary = '2' ", "Mango = '1' and Mango = '2'", "Mark = '1' and Mark= '2'")),

                 class = "data.frame", row.names = c(NA, 
                                                     -3L))

现在,我确实想遍历此列中称为Branching_Logic的行,并仅过滤出具有此模式的行,例如row1具有 [Silva ='1'和Silva ='2']

我尝试使用dplyr解决问题,但出现错误第1列具有NA名称

df$Branching_Logic <- rownames(diff_df)
df %>%
  filter(str_detect(Branching_Logic, 'and'))

预期结果是一个数据框,该数据框在Branching_Logic列中具有经过过滤的行,且具有该模式,如此表中所示

dput(df)
df<-structure(list(column1 = c("John", "Jane", "Erick"),
                   column2 = c("J34", "J345", "Er456"),
                   New_BranchingLogic = c("Silva = '1' and Silva = '2' ", "Mango = '1' and Mango = '2' ", "Mark = '1' and Mark= '2'")),

                 class = "data.frame", row.names = c(NA, 
                                                     -3L))

0 个答案:

没有答案