Add column to DataFrame in sparkR

前端 未结 2 538
栀梦
栀梦 2021-01-11 11:00

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         


        
2条回答
  •  感动是毒
    2021-01-11 11:34

    The straight solution will be to use SparkR::lit() function:

    df_new = withColumn(df, "new_column_name", lit("N"))
    

    Edit 7/17/2019

    In newer Spark versions, the following also works:

    df1$new_column <- "N"
    df1[["new_column"]] <- "N"
    

提交回复
热议问题