What's the R statement responding to SQL's 'in' statement?

前端 未结 2 1137
慢半拍i
慢半拍i 2021-01-14 10:22

a case

df=data.frame(id=c(101,102,102,103,104,104,104),
         calmonth=c(\'01\',\'01\',\'01\',\'01\',\'01\',\'01\',\'02\'),
         product=c(\'         


        
2条回答
  •  别那么骄傲
    2021-01-14 11:19

    If you prefer SQL syntax then use sqldf package:

    library(sqldf)
    sqldf("
          select * 
          from (
                select id,
                       calmonth,
                       group_concat(product, ' & ') product
                from df
                group by id, calmonth
               ) 
          where product='apple & htc' and
                calmonth='01'
          ")
    

提交回复
热议问题