https://researchdatapod.com/how-to-solve-r-error-in-apply-dimx-must-have-a-positive-length/
How to Solve R Error in apply: dim(X) must have a positive length