简体   繁体   中英

How to pass vector of column names into multidplyr's partition function in R

I am facing an issue with multidplyr's partition function. My objective is to find the summary statistics by group of column names. ex:

rcols <- c("cyl","am","vs")

Now I wanted to find summary statistics by using above rcols object. I can do it in dplyr by using following lines.

df <- mtcars %>% group_by(.dots=rcols) %>% summarise(Mean=mean(mpg))

Now I wanted to do the same by using multidplyr package.

df <- mtcars %>% partition(rcols) %>% summarise(Mean=mean(mpg)) %>% collect()

But the above line is not working as expected.

Can anyone help me on this issue?

Thanks in advance.

We have to create a text with the required query.

library(dplyr)
library(multidplyr)

rcols <- c("cyl","am","vs")
k1<-paste("d1<-mtcars%>%partition(",paste(rcols,collapse=","),")%>%summarise(Mean=mean(mpg))%>%collect()",sep="")
k2<-eval(parse(text=k1))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM