我正在尝试使用sparkR将数据框中的列类型从integer更改为double。使用cast()函数进行类型转换时,出现以下错误。
printSchema(df)
root
|-- col1: string (nullable = true)
|-- col2: integer (nullable = true)
代码:
> df$col2 <- cast(df$col2, "double")
错误:
Error in data[subset, , drop = FALSE] :
object of type 'S4' is not subsettable
pyspark
比SparkR
我更熟悉,但我认为您应该这样做:
df <- withColumn(df,"col2",cast(df$col2,"double"))
现在,我可以通过在cast()方法之前添加SparkR ::来解决上述错误。
> df$col2 <- SparkR::cast(df$col2, "double")