Search code examples
rapache-sparksparkrsparklyr

Error in rep(xi, length.out = nvar) : attempt to replicate an object of type 'S4'


I'm Unable to a rbind on two dataframes.

I created one using the other dataframe, like this,data1 is my original dataframe. With same column names and order

s1 <- data.frame(A =rep(first(data1)[[1]],9),
              B=rep(first(data1)[[2]],9),
              C = rep(first(data1)[[3]],9),
              D = rep(first(data1)[[4]],9),
              E = rep(first(data1)[[5]],9),
              F = rep(first(data1)[[6]],9),
              G = rep(first(data1)[[7]],9),
              H = rep(first(data1)[[8]],9),
              I = forecast_month_ext(first(data1)[[8]]),
              K=rep(0,9))

The above code gave me a dataframe i wanted. I'm not able to bind this and the original one. It's throwing an error.

Error in rep(xi, length.out = nvar) : attempt to replicate an object of type 'S4' I took top 9 rows of the dataframe and tried rbind. It threw same error. Rbind code

datax<-rbind(data,s1)

I even tried this with no success.

data<-rbind(data,s1)

Solution

  • s1 <- createDataFrame(data.frame(A =rep(first(data1)[[1]],9),
              B=rep(first(data1)[[2]],9),
              C = rep(first(data1)[[3]],9),
              D = rep(first(data1)[[4]],9),
              E = rep(first(data1)[[5]],9),
              F = rep(first(data1)[[6]],9),
              G = rep(first(data1)[[7]],9),
              H = rep(first(data1)[[8]],9),
              I = forecast_month_ext(first(data1)[[8]]),
              K=rep(0,9)))
    

    createDataFrame() - I missed this.

    Adding this as it can help anyone coming in search