Adds nil check in lua avg method.

Similar to https://github.com/skydb/sky/commit/d4860738 this PR fixes the avg function. Please review @snormore @benbjohnson