Variance in Weather in R - can't find function "variance"

Hello,

I’m working on the project https://www.codecademy.com/courses/learn-r/projects/variance-in-weather-r.

I made it to step 5 with no problems, but when I used the code to calculate variance, I get the following message:

Error in variance(temp): could not find function "variance"

I double-checked my code with what the hint suggested, and it’s exactly the same: temperature_var <- variance (temp)
I even copied and pasted to make sure there wasn’t some tiny typo, and still the same result.

I had no problems with using the mean earlier. Can anyone figure out what the problem is? Is it a problem with my code, or a bug in Codecademy?

For reference, here is all the code I’ve done so far:

head(london_data)
nrow(london_data)

temp <- london_data$TemperatureC

average_temp <- mean(temp)
average_temp

temperature_var <- variance(temp)
temperature_var

Thanks

Hello, @object8252857956, welcome to the forums.

If you’ve completed the lesson, https://www.codecademy.com/courses/learn-r/lessons/variance-r/exercises/variance, you learned how to calculate variance, and followed the steps to construct a function that calculates variance.

The fifth exercise, https://www.codecademy.com/courses/learn-r/lessons/variance-r/exercises/variance-in-r, has a fully functional variance function.

The error is because there is no function named variance in your current code. You can go back, and copy the function from the fifth exercise in the variance lesson, or just re-write it if you remember the formula. It likely was an oversight on CC’s part to not have it included in the project’s skeleton code.

1 Like

Thank you! I completely overlooked that Codecademy made the function in section 5, and that it wasn’t built in.

2 Likes