2
我想在sparklyr中使用group_by()和mutate()函數來連接組中的行。Sparklyr:使用group_by,然後連接來自組中的行的字符串
下面是一個簡單的例子,我覺得應該工作,但不會:
library(sparkylr)
d <- data.frame(id=c("1", "1", "2", "2", "1", "2"),
x=c("200", "200", "200", "201", "201", "201"),
y=c("This", "That", "The", "Other", "End", "End"))
d_sdf <- copy_to(sc, d, "d")
d_sdf %>% group_by(id, x) %>% mutate(y = paste(y, collapse = " "))
我想什麼它產生的是:
Source: local data frame [6 x 3]
Groups: id, x [4]
# A tibble: 6 x 3
id x y
<fctr> <fctr> <chr>
1 1 200 This That
2 1 200 This That
3 2 200 The
4 2 201 Other End
5 1 201 End
6 2 201 Other End
我得到以下錯誤:
Error: org.apache.spark.sql.AnalysisException: missing) at 'AS' near '' '' in selection target; line 1 pos 42
請注意,在data.frame上使用相同的代碼工作正常:
會將您的命令給sql
聲明 -
d %>% group_by(id, x) %>% mutate(y = paste(y, collapse = " "))
謝謝,非常有用的答案 – Maggie