dapply {SparkR} | R Documentation |
Apply a function to each partition of a SparkDataFrame.
dapply(x, func, schema) ## S4 method for signature 'SparkDataFrame,'function',characterOrstructType' dapply(x, func, schema)
x |
A SparkDataFrame |
func |
A function to be applied to each partition of the SparkDataFrame. func should have only one parameter, to which a R data.frame corresponds to each partition will be passed. The output of func should be a R data.frame. |
schema |
The schema of the resulting SparkDataFrame after the function is applied. It must match the output of func. Since Spark 2.3, the DDL-formatted string is also supported for the schema. |
dapply since 2.0.0
Other SparkDataFrame functions:
SparkDataFrame-class
,
agg()
,
alias()
,
arrange()
,
as.data.frame()
,
attach,SparkDataFrame-method
,
broadcast()
,
cache()
,
checkpoint()
,
coalesce()
,
collect()
,
colnames()
,
coltypes()
,
createOrReplaceTempView()
,
crossJoin()
,
cube()
,
dapplyCollect()
,
describe()
,
dim()
,
distinct()
,
dropDuplicates()
,
dropna()
,
drop()
,
dtypes()
,
exceptAll()
,
except()
,
explain()
,
filter()
,
first()
,
gapplyCollect()
,
gapply()
,
getNumPartitions()
,
group_by()
,
head()
,
hint()
,
histogram()
,
insertInto()
,
intersectAll()
,
intersect()
,
isLocal()
,
isStreaming()
,
join()
,
limit()
,
localCheckpoint()
,
merge()
,
mutate()
,
ncol()
,
nrow()
,
persist()
,
printSchema()
,
randomSplit()
,
rbind()
,
rename()
,
repartitionByRange()
,
repartition()
,
rollup()
,
sample()
,
saveAsTable()
,
schema()
,
selectExpr()
,
select()
,
showDF()
,
show()
,
storageLevel()
,
str()
,
subset()
,
summary()
,
take()
,
toJSON()
,
unionByName()
,
union()
,
unpersist()
,
withColumn()
,
withWatermark()
,
with()
,
write.df()
,
write.jdbc()
,
write.json()
,
write.orc()
,
write.parquet()
,
write.stream()
,
write.text()
## Not run:
##D df <- createDataFrame(iris)
##D df1 <- dapply(df, function(x) { x }, schema(df))
##D collect(df1)
##D
##D # filter and add a column
##D df <- createDataFrame(
##D list(list(1L, 1, "1"), list(2L, 2, "2"), list(3L, 3, "3")),
##D c("a", "b", "c"))
##D schema <- structType(structField("a", "integer"), structField("b", "double"),
##D structField("c", "string"), structField("d", "integer"))
##D df1 <- dapply(
##D df,
##D function(x) {
##D y <- x[x[1] > 1, ]
##D y <- cbind(y, y[1] + 1L)
##D },
##D schema)
##D
##D # The schema also can be specified in a DDL-formatted string.
##D schema <- "a INT, d DOUBLE, c STRING, d INT"
##D df1 <- dapply(
##D df,
##D function(x) {
##D y <- x[x[1] > 1, ]
##D y <- cbind(y, y[1] + 1L)
##D },
##D schema)
##D
##D collect(df1)
##D # the result
##D # a b c d
##D # 1 2 2 2 3
##D # 2 3 3 3 4
## End(Not run)