y = range(x$VALUE) to
y = range(x$VALUE, na.rm=TRUE) to remove
NA missing values.
You have another problem, namely that in both functions you refer to
ind[[i]], which I assume means at some point this code was part of a loop. My guess is all the references to
ind[[i]] should be