Add column to DataFrame in sparkR

匿名 (未验证) 提交于 2019-12-03 02:24:01

问题:

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 <- "N" 

But with SparkR, I get the following error :

Error: class(value) == "Column" || is.null(value) is not TRUE 

I've tried insane things to manage it, I was able to create a column using another (existing) one with df <- withColumn(df, "new_column", df$existing_column), but this simple thing, nope...

Any help ?

Thanks.

回答1:

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

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


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