我正在使用SparkR 2.1.0进行数据处理
我希望以编程方式按多列分组。我知道如果我单独列出它们,我可以按多列分组,或者从向量中引用它们的位置......但我希望能够将列列表作为向量传递(这样,函数会自动调整为我传递的论据数量)
cpny <- c("Fakeco1", "Fakeco2", "Fakeco3", "Fakeco4", "Fakeco5", "Fakeco6")
state <- c("CA", "NY", "WA", "CA", "CA", "NY")
public <- c("Y", "Y", "N", "N", "N", "N")
color <- c("White", "Red", "Green", "Green", "Green", "Red")
revs <- c(400, 200, 900, 500, 200, 120)
df <- data.frame(cpny, state, public, color, revs)
# Convert to SparkR dataframe
df_s <- as.DataFrame(df)
df_grouped <- df_s %>%
groupBy('state', 'public') %>%
summarize(sum_Revs = sum(df_s$revs))
group_vars <- c('state', 'public')
df_grouped <- df_s %>%
groupBy(group_vars[[1]], group_vars[[2]]) %>%
summarize(sum_Revs = sum(df_s$revs))
group_vars <- c('state', 'public')
df_grouped <- df_s %>%
groupBy(group_vars) %>%
summarize(sum_Revs = sum(df_s$revs))
任何解决方案或其他想法?
答案 0 :(得分:1)
您可以使用do.call()https://stat.ethz.ch/R-manual/R-devel/library/base/html/do.call.html并将列和数据框放入列表中。以下适用于我:
DataRow rowstate == modified