[R] sapply returning list instead of matrix

Bert Gunter gunter.berton at gene.com
Fri Jan 31 22:44:53 CET 2014

As you ignored the posting guide and posted in HTML, your "below"
didn't get through. So one can only guess that it has something to do
with (see ?sapply)

"Simplification in sapply is only attempted if X has length greater
than zero and if the return values from all elements of X are all of
the same (positive) length. If the common length is one the result is
a vector, and if greater than one is a matrix with a column
corresponding to each element of X. "

Return values most also be of the same type, also, obviously.


Bert Gunter
Genentech Nonclinical Biostatistics
(650) 467-7374

"Data is not information. Information is not knowledge. And knowledge
is certainly not wisdom."
H. Gilbert Welch

On Fri, Jan 31, 2014 at 1:36 PM, chris warth <cswarth at gmail.com> wrote:
> Can anyone suggest a rationale for why sapply() returns different types
> (list and matrix) in the two examples below?   Is there any way to get
> sapply() or any other apply() function to return a matrix in both cases?
> simplify=TRUE doesn't change the outcome.
> I understand why it is happening, I just can't understand why such
> unpredictable behavior makes sense.
>         [[alternative HTML version deleted]]
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

More information about the R-help mailing list