Add column to DataFrame in sparkR

眉间皱痕 提交于 2019-12-01 02:48:36
Dmitriy Selivanov

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"

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

df$new_column <- lit("N")
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!