Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 206235

How to group by multiple values in a function with dplyr

$
0
0

I wonder how to modify below code

xxx<-function(df,groupbys){
  groupbys<-enquo(groupbys)
    df%>%group_by_(groupbys)%>%summarise(count=n())
  }

zzz<-xxx(iris,Species)

to have the option to feed in either one column or more than one column to group by? For example, goup_by_ both Speciesand Petal.Length with iris dataset.


Viewing all articles
Browse latest Browse all 206235

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>