Skip to content

From data frame to list object

2 messages · David Winsemius

#
On Jan 31, 2011, at 2:18 PM, Bogaso Christofer wrote:

            
It is a job for split. The result is a data.frame but that is, after  
all, just a list with certain attributes.

 > split(dfrm, dfrm$y)
$a
             x y z
1 -1.16790385 a x
2 -0.84831139 a x
3 -0.64312051 a y
4 -1.66841121 a y
5  0.03737404 a z
6 -0.42165643 a z

$b
             x y z
7   1.1045024 b x
8   1.4787933 b x
9   0.5278083 b y
10  0.1770083 b y
11 -0.5054573 b z
12 -0.6512499 b z

$c
              x y z
13  0.61225420 c x
14 -0.45032691 c x
15  0.36502921 c y
16  0.33505288 c y
17  0.02189088 c z
18 -0.53893624 c z

 > str(split(dfrm, dfrm$y)$a)
'data.frame':	6 obs. of  3 variables:
  $ x: num  -1.1679 -0.8483 -0.6431 -1.6684 0.0374 ...
  $ y: Factor w/ 3 levels "a","b","c": 1 1 1 1 1 1
  $ z: Factor w/ 3 levels "x","y","z": 1 1 2 2 3 3
#
On Jan 31, 2011, at 2:26 PM, David Winsemius wrote:

            
Er, the result is a list of dataframes.
David Winsemius, MD
West Hartford, CT