Help with error, not sure why

library("readxl")

data<-read_excel("SolarPrediction(USE).xls")

radiation<-data[,1]
temperature<-data[,2]
pressure<-data[,3]
humidity<-data[,4]
windspeed<-data[,5]

m1 <- lm(formula=radiation~temperature+pressure+humidity+windspeed)
summary(m1)

Why is it when I run the m1 code does it spit out this error: Error in model.frame.default(formula = radiation ~ temperature + pressure + :
invalid type (list) for variable 'radiation'

I repeated what my professor has done many times so I am not sure why I am getting this error. Is it because I am importing an excel file?

What does data look like?

Can you provide an example of it using dput or reprex?

read_excel should return a tibble (flavor of data frame). Check with

class(data)

If that works, re-read into variable named dat. data is a built-in function, and there are operations that will treat it as a closure.

Don't subset out the variables. Instead

fit <- lm(radiation ~ temperature + pressure + humidity + windspeed, data = dat)

or

fit <- lm(radiation ~., data = dat)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.