我有以下数据框,我的目的是找到所有具有不同用法但类型相同的 ID。
ID <- rep(1:4, each=3)
USAGE <- c("private","private","private","private",
"taxi","private","taxi","taxi","taxi","taxi","private","taxi")
TYPE <- c("VW","VW","VW","VW","MER","VW","VW","VW","VW","VW","VW","VW")
df <- data.frame(ID,USAGE,TYPE)
如果我跑
df %>% group_by(ID, TYPE) %>% filter(n_distinct(USAGE)>1)
我得到了预期的结果。但是我的原始数据框有超过 200 万行。所以我想用我所有的核心来运行这个操作。
我用multidplyr尝试了这段代码:
f1 <- partition(df, ID)
f2 <- f1 %>% group_by(ID, TYPE) %>% filter(n_distinct(USAGE)>1)
f3 <- collect(f2)
但随后出现以下消息:
Warning message: group_indices_.grouped_df ignores extra arguments
后
f1 <- partition(df, ID)
和
Error in checkForRemoteErrors(lapply(cl, recvResult)) :
4 nodes produced errors; first error: Evaluation error: object 'f1' not found.
后
f2 <- f1%>% group_by(ID, TYPE) %>% filter(f1, n_distinct(USAGE)>1)
将整个操作实施到 multidplyr 的正确方法是什么?非常感谢。