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

184 views Asked by At

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.

1

There are 1 answers

0
789372u On BEST ANSWER

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))