withColumn {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(.data, ...)

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

mutate(.data, ...)

transform(`_data`, ...)

withColumn(x, colName, col)

Arguments

x

A DataFrame

colName

A string containing the name of the new column.

col

A Column expression.

.data

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
##D newDF2 <- transform(df, newCol = df$col1 / 5, newCol2 = df$col1 * 2)
## End(Not run)

[Package SparkR version 1.5.2 Index]