Add column to DataFrame in sparkR

前端 未结 2 528
栀梦
栀梦 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"
    
    0 讨论(0)
  • 2021-01-11 11:36

    There's an easier way to use SparkR::lit() that more closely mimics the syntax you tried first:

    df$new_column <- lit("N")
    
    0 讨论(0)
提交回复
热议问题