mutate {SparkR}R Documentation

Mutate

Description

Return a new SparkDataFrame with the specified columns added or replaced.

Usage

mutate(.data, ...)

transform(`_data`, ...)

## S4 method for signature 'SparkDataFrame'
mutate(.data, ...)

## S4 method for signature 'SparkDataFrame'
transform(`_data`, ...)

Arguments

.data

A SparkDataFrame

col

a named argument of the form name = col

Value

A new SparkDataFrame with the new columns added or replaced.

See Also

rename withColumn

Other SparkDataFrame functions: SparkDataFrame-class, [[, agg, arrange, as.data.frame, attach, cache, collect, colnames, coltypes, columns, count, dapply, describe, dim, distinct, dropDuplicates, dropna, drop, dtypes, except, explain, filter, first, group_by, head, histogram, insertInto, intersect, isLocal, join, limit, merge, ncol, persist, printSchema, registerTempTable, rename, repartition, sample, saveAsTable, selectExpr, select, showDF, show, str, take, unionAll, unpersist, withColumn, write.df, write.jdbc, write.json, write.parquet, write.text

Examples

## Not run: 
##D sc <- sparkR.init()
##D sqlContext <- sparkRSQL.init(sc)
##D path <- "path/to/file.json"
##D df <- read.json(sqlContext, path)
##D newDF <- mutate(df, newCol = df$col1 * 5, newCol2 = df$col1 * 2)
##D names(newDF) # Will contain newCol, newCol2
##D newDF2 <- transform(df, newCol = df$col1 / 5, newCol2 = df$col1 * 2)
##D 
##D df <- createDataFrame(sqlContext, 
##D                       list(list("Andy", 30L), list("Justin", 19L)), c("name", "age"))
##D # Replace the "age" column
##D df1 <- mutate(df, age = df$age + 1L)
## End(Not run)

[Package SparkR version 2.0.0 Index]