Error in eval(predvars, data, env) : object 'charges' not found

4) Scroll down to lines 37, and change the code based on the model you specified (only one independent variable-- AgeOfHouse).

fit <- lm(charges ~ bmi, data = mydata)


• You will need to add a new column (AgeOfHouse=2019- yr_built) in the dataset and save your changes before running the script

My entire code:

rm(list = ls());
mydata <- read.csv("kc_house_data (1).csv",header=TRUE)
sink("RegressionOutput.txt", append=FALSE, split=TRUE)
plot(charges ~ bmi, data = mydata)
mydata$AgeOfHouse <- 2019-yr_built
fit <- lm(charges ~ AgeOfHouse, data = mydata)
mydata$ <- predict(fit)
plot(charges ~, data = mydata)
pairs(charges~ bmi + age + male + children + smoker, data = mydata)
res <- cor(mydata)

round(res, 2)
mfit <- lm(charges~ bmi + age + male + children + smoker, data = mydata)


mydata$charges.mfit <- predict(mfit)

plot(charges ~ charges.mfit, data = mydata)

Hi, and welcome!

Please see the FAQ: What's a reproducible example (`reprex`) and how do I do one? Using a reprex, complete with representative data will attract quicker and more answers. Also, please review the homework policy.

What did you have in your namespace, as shown by ls() before

rm(list = ls());

Was mydata there? Is it still there?

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