Learn R Programming

SparkR (version 3.1.2)

withField: withField

Description

Adds/replaces field in a struct Column by name.

Usage

withField(x, fieldName, col)

# S4 method for Column,character,Column withField(x, fieldName, col)

Arguments

x

a Column

fieldName

a character

col

a Column expression

Examples

Run this code
# NOT RUN {
df <- withColumn(
  createDataFrame(iris),
  "sepal",
   struct(column("Sepal_Width"), column("Sepal_Length"))
)

head(select(
  df,
  withField(df$sepal, "product", df$Sepal_Length * df$Sepal_Width)
))
# }

Run the code above in your browser using DataLab