[R] matrix from list
lefevrol at yahoo.com
Sun Apr 27 17:59:35 CEST 2008
It's true one may have to set some rules but I think you are blowing it up.
First, it is true one would have to agree for list[[vec]] to always return
a matrix but it is the useful behaviour since you can already get a vector
Second, as to the raggedness, matrix(), array() and probably other methods
already have rules to deal with it, i.e., they cycle and post a warning if
the desired length is not a multiple of the length of the supplied
"prototype". You'd get a matrix of the length of the longest selected list
element; anything else would be baroque.
Third, as to heterogeneity, matrix() and as.matrix() already face the same
issue and so have a set of coercion rules to deal with it; when they can't
they throw an error.
Lastly, you are correct that I had overlooked the problem of nested lists
and that one need (at least I think so) to make some non-obvious rules to
decided how to flatten them. So you'd throw an error in that case.
In short I think array [] indexing would still be well-defined for data
frames and non-nested lists, with no need for new and special rules. Given
the existence of alternatives it might or might not be very useful but it
would remove the shock factor of an indexing operator that does not take
More information about the R-help