R code for calculating metabolism from sensors