[Rd] simplify2array(higher=TRUE, listOfSingleRowDataframes)

William Dunlap wdunlap at tibco.com
Mon Mar 13 19:10:23 CET 2017

I noticed that simplify2array acted oddly when given a list of
data.frames of various sizes.  If the data.frames have one row, it
makes a new first dimension with the dimname equal to
rownames(firstDataframe).  That dimension does not appear for
data.frames with other numbers of rows.

> str(dimnames(sapply(345:346, function(i)data.frame(X=101, Y=201, row.names=paste0("Row",1)), simplify="array")))
List of 3
 $ : chr "Row1"
 $ : chr [1:2] "X" "Y"
 $ : NULL
> str(dimnames(sapply(345:346, function(i)data.frame(X=numeric(), Y=numeric(0), row.names=character()), simplify="array")))
List of 2
 $ : chr [1:2] "X" "Y"
 $ : NULL
> str(dimnames(sapply(345:346, function(i)data.frame(X=101:102, Y=201:202, row.names=paste0("Row",1:2)), simplify="array")))
List of 2
 $ : chr [1:2] "X" "Y"
 $ : NULL

The extra dimension does not appear if I convert those data.frames to lists.

It does appear if I convert those data.frames to matrices and the
number of rows is not zero (in which case there are no dims or

Is this pattern of behavior intended?

Bill Dunlap
TIBCO Software
wdunlap tibco.com

More information about the R-devel mailing list