Closed stefvanbuuren closed 1 month ago
Another option is to use something like the following, which might be a bit cleaner (removing the if-else construction):
yvar <- blocks[[j]]
y <- data[, yvar, drop=FALSE]
def <- apply(y, 2, assign.method)
...
I haven't tested this through, but y
should now be a matrix
or data.frame
and apply loops over its columns.
In
make.method()
there is a piece of inefficient code that makes it unnecessary slow for large datasets (high n):The idea of
supply(y, assign.method)
is to test the variable type of all variables in the block, and assign the same method if these have the same types. However, ifblocks[[j]]
contains only one variable (which is almost always the case), thenassign.method()
is called for every data point in they
vector, which is highly inefficient.The solution is to skip over the
sapply()
statement for single-variable blocks.