withColumn {SparkR}R Documentation

WithColumn

Description

Return a new SparkDataFrame by adding a column or replacing the existing column that has the same name.

Usage

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

withColumn(x, colName, col)

Arguments

x

A SparkDataFrame

colName

A column name.

col

A Column expression.

Value

A SparkDataFrame with the new column added or the existing column replaced.

See Also

rename mutate

Other SparkDataFrame functions: $, $<-, select, select, select,SparkDataFrame,Column-method, select,SparkDataFrame,list-method, selectExpr; SparkDataFrame-class, dataFrame; [, [[, subset; agg, agg, count,GroupedData-method, summarize, summarize; arrange, arrange, arrange, orderBy, orderBy, orderBy, orderBy; as.data.frame, as.data.frame,SparkDataFrame-method; attach, attach,SparkDataFrame-method; cache; collect; colnames, colnames, colnames<-, colnames<-, columns, names, names<-; coltypes, coltypes, coltypes<-, coltypes<-; columns, dtypes, printSchema, schema, schema; count, nrow; dapply, dapply, dapplyCollect, dapplyCollect; describe, describe, describe, summary, summary, summary,AFTSurvivalRegressionModel-method, summary,GeneralizedLinearRegressionModel-method, summary,KMeansModel-method, summary,NaiveBayesModel-method; dim; distinct, unique; dropDuplicates, dropDuplicates; dropna, dropna, fillna, fillna, na.omit, na.omit; drop, drop; dtypes; except, except; explain, explain; filter, filter, where, where; first, first; groupBy, groupBy, group_by, group_by; head; histogram; insertInto, insertInto; intersect, intersect; isLocal, isLocal; join; limit, limit; merge, merge; mutate, mutate, transform, transform; ncol; persist; printSchema; rbind, rbind, unionAll, unionAll; registerTempTable, registerTempTable; rename, rename, withColumnRenamed, withColumnRenamed; repartition; sample, sample, sample_frac, sample_frac; saveAsParquetFile, saveAsParquetFile, write.parquet, write.parquet; saveAsTable, saveAsTable; saveDF, saveDF, write.df, write.df, write.df; selectExpr; showDF, showDF; show, show, show,GroupedData-method, show,WindowSpec-method; str; take; unpersist; write.jdbc, write.jdbc; write.json, write.json; write.text, write.text

Examples

## Not run: 
sc <- sparkR.init()
sqlContext <- sparkRSQL.init(sc)
path <- "path/to/file.json"
df <- read.json(sqlContext, path)
newDF <- withColumn(df, "newCol", df$col1 * 5)
# Replace an existing column
newDF2 <- withColumn(newDF, "newCol", newDF$col1)

## End(Not run)

[Package SparkR version 2.0.0 Index]