Reputation: 1085
I am trying to change column type in data frame from integer to double using sparkR. while typecasting using cast() function getting below error.
printSchema(df)
root
|-- col1: string (nullable = true)
|-- col2: integer (nullable = true)
Code:
> df$col2 <- cast(df$col2, "double")
Error:
Error in data[subset, , drop = FALSE] :
object of type 'S4' is not subsettable
Upvotes: 1
Views: 715
Reputation: 1085
Now i able to fix the above error by adding SparkR:: before cast() method.
> df$col2 <- SparkR::cast(df$col2, "double")
Upvotes: 1
Reputation: 6226
I am more familiar with pyspark
than SparkR
but I think you should do:
df <- withColumn(df,"col2",cast(df$col2,"double"))
Upvotes: 1