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
?
Why reprex?
Getting unstuck is hard. Your first step here is usually to create a reprex, or reproducible example. The goal of a reprex is to package your code, and information about your problem so that others can run it and feel your pain. Then, hopefully, folks can more easily provide a solution.
What's in a Reproducible Example?
Parts of a reproducible example:
background information - Describe what you are trying to do. What have you already done?
complete set up - include any library() calls and data to reproduce your issue.
data for a reprex: Here's a discussion on setting up data for a reprex
make it run - include the minimal code required to reproduce your error on the data…
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)
system
Closed
October 23, 2020, 1:30am
4
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.