From wdunlap at tibco.com  Mon Mar 13 19:10:23 2017
From: wdunlap at tibco.com (William Dunlap)
Date: Mon, 13 Mar 2017 11:10:23 -0700
Subject: [Rd] simplify2array(higher=TRUE, listOfSingleRowDataframes)
Message-ID: <CAF8bMcaZCn6zObOStYUL+W8AP=OdjA8HMq6OtB52CTtT6X6Org@mail.gmail.com>

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
dimnames).

Is this pattern of behavior intended?

Bill Dunlap
TIBCO Software
wdunlap tibco.com



[Rd] simplify2array(higher=TRUE, listOfSingleRowDataframes)
William Dunlap