Trying to replicate Ben Jann's Stata decompose routine in R