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


I’m working on the project

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:


temp <- london_data$TemperatureC

average_temp <- mean(temp)

temperature_var <- variance(temp)


1 Like

Hello, @object8252857956, welcome to the forums.

If you’ve completed the lesson,, you learned how to calculate variance, and followed the steps to construct a function that calculates variance.

The fifth exercise,, 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.


I made the same mistake. If you click the hint you’d think it’s a built in function too.