That error usually implies you don’t have an object (or column in a data frame) named ‘avg’, your line of code also didn’t mention avg.
It would help if you asked this with a minimal REPRoducible EXample (reprex)? A reprex makes it much easier for others to understand your issue and figure out how to help.