1

Say I want to write a function to delete a column from a SparkR DataFrame(Version 1.6.0):

dropColumn <- function(df, col) { df[[col]] <- NULL df } df <- dropColumn(df, 'Email') 

But it would error out:

Error in `[[<-`(`*tmp*`, col, value = NULL) : [[<- defined for objects of type "S4" only for subclasses of environment 

How can I change my code fix it?

2
  • Open JIRA, implement required method on DataFrame, make PR? Commented Feb 29, 2016 at 22:22
  • I mean there is not much you can do about it here. DataFrame simply doesn't implement [[<-. Commented Feb 29, 2016 at 22:53

1 Answer 1

0

There's currently no convenience method in dataframe for dropping a column. I think this would work for now until it could could be implemented in SparkR:

dropColumn <- function(df, col) { tempdf <- new("DataFrame", sdf=SparkR:::callJMethod(df@sdf, "drop", col), isCached=FALSE) tempdf } newdf <- dropColumn(inputdf, 'Email') 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.