0
train <- read.csv("train.csv", strings=T)
test <- read.csv("test.csv", strings=T)

library(gamlr)

allX <- rbind(train[,-c(1,81)],test[-1])

allXnaref <- naref(allX, impute=T)

modMat <- sparse.model.matrix(~., data=allXnaref)[,-1]

This is my code for right now. When I run all the code above and then run the modMat code it gives me this error message:

Error in as.data.frame.default(data, optional = TRUE) : 
cannot coerce class ‘"function"’ to a data.frame

I am stuck on what to do or fix because the code above is all correct. Do I need to fix something within my gamlr or in the code itself?

I have been trying to understand the error but on other computers the code works but does not work on mine. I have been trying the code over and over but my Professor and I are stuck on what is wrong with the code.

MrFlick
  • 195,160
  • 17
  • 277
  • 295
  • 2
    What is "the modMat code"? If the error happens after you run that, then you should show it to us. It's even better if you can simplify things so that we can run your code and see the error for ourselves: create fake datasets, don't read them from files we don't have. – user2554330 Apr 19 '23 at 16:12
  • It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. Include the `library()` calls for all non-base R packages you are using. – MrFlick Apr 19 '23 at 17:32
  • Do you know what `as` is? Both what it is supposed to be, and what it actually is? You may need to look at the full error message (even add it to the question) to see how this error line relates to your code. – hpaulj Apr 19 '23 at 18:18
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Apr 25 '23 at 08:50

0 Answers0