The error
# dim(X) must have a positive length
clearly states the x value must be in a dimension of a matrix or an array. The apply function is not for vectors. If not resolved, you can try with a function all .
apply
all