When trying to downsample a matrix with n rows to any value ≥ 0.5 n, the following error is returned:
Error in apply(data[floor(i * bin_width + 1:bin_width), ], 2, mean) :
dim(X) must have a positive length
Steps to reproduce:
n = 20
data = data.frame(X=seq_len(n), Y=rnorm(n))
LTTB(data, n_bins=n/2) # Error
LTTB(data, n_bins=n/2 - 1) # Works fine
[Imported from https://github.com/javiljoen/LTTB/issues/2]
Here is a function for correctly splitting the data into bins (similar to
numpy.array_split
):