Selecting data frame rows based on partial string match in a column

后端 未结 4 1053
轻奢々
轻奢々 2020-11-22 09:16

I want to select rows from a data frame based on partial match of a string in a column, e.g. column \'x\' contains the string "hsa". Using sqldf -

4条回答
  •  悲哀的现实
    2020-11-22 10:04

    Another option would be to simply use grepl function:

    df[grepl('er', df$name), ]
    CO2[grepl('non', CO2$Treatment), ]
    
    df <- data.frame(name = c('bob','robert','peter'),
                     id = c(1,2,3)
                     )
    
    # name id
    # 2 robert  2
    # 3  peter  3
    

提交回复
热议问题