withColumn,DataFrame,character,Column-method {SparkR}R Documentation

WithColumn

Description

Return a new DataFrame with the specified column added.

Return a new DataFrame with the specified columns added.

Usage

## S4 method for signature 'DataFrame,character,Column'
withColumn(x, colName, col)

## S4 method for signature 'DataFrame'
mutate(x, ...)

mutate(x, ...)

withColumn(x, colName, col)

Arguments

x

A DataFrame

colName

A string containing the name of the new column.

col

A Column expression.

x

A DataFrame

col

a named argument of the form name = col

Value

A DataFrame with the new column added.

A new DataFrame with the new columns added.

Examples

## Not run: 
##D sc <- sparkR.init()
##D sqlContext <- sparkRSQL.init(sc)
##D path <- "path/to/file.json"
##D df <- jsonFile(sqlContext, path)
##D newDF <- withColumn(df, "newCol", df$col1 * 5)
## End(Not run)
## Not run: 
##D sc <- sparkR.init()
##D sqlContext <- sparkRSQL.init(sc)
##D path <- "path/to/file.json"
##D df <- jsonFile(sqlContext, path)
##D newDF <- mutate(df, newCol = df$col1 * 5, newCol2 = df$col1 * 2)
##D names(newDF) # Will contain newCol, newCol2
## End(Not run)

[Package SparkR version 1.4.1 Index]