I would like to add a column filled with a character N
in a DataFrame in SparkR. I would do it like that with non-SparkR code :
df$new_column &l
The straight solution will be to use SparkR::lit()
function:
df_new = withColumn(df, "new_column_name", lit("N"))
In newer Spark versions, the following also works:
df1$new_column <- "N"
df1[["new_column"]] <- "N"
There's an easier way to use SparkR::lit()
that more closely mimics the syntax you tried first:
df$new_column <- lit("N")