[R] swapping with data.frame

Randy Zelick zelickr at pdx.edu
Tue Jun 1 19:55:24 CEST 2004


Hi there,

I have some data which are convenient to enter as lists. For example:

t1<-list(fname="animal1",testname="hyla",dspkr="left",res1=39.7,res2=15.0)
t2<-list(fname="animal1",testname="bufo",dspkr="left",res1=14.4,res2=56.1)
t3<-list(fname="animal2",testname="hyla",dspkr="right",res1=22.6,res2=11.8)

I would like to generate a dataframe, but *not* the way this approach
works...

fdf<-data.frame(t1,t2,t3)

fdf

    fname testname dspkr res1 res2   fname testname dspkr res1 res2 ...
1 animal1     hyla  left 39.7   15 animal1     bufo  left 14.4 56.1 ...


Instead, what I would like is:

     fname   testname   dspkr   res1    res2

t1 animal1       hyla    left   39.7    15.0
t2 animal1       bufo    left   14.4    56.1
t3 animal2       hyla   right   22.6    11.8


or this would be fine too...

    x   fname   testname   dspkr   res1    res2

1  t1 animal1       hyla    left   39.7    15.0
2  t2 animal1       bufo    left   14.4    56.1
3  t3 animal2       hyla   right   22.6    11.8

Is there a practical (hopefully simple) way to do this?

Thanks,

=Randy=

R. Zelick				email: zelickr at pdx.edu
Department of Biology			voice: 503-725-3086
Portland State University		fax:   503-725-3888

mailing:
P.O. Box 751
Portland, OR 97207

shipping:
1719 SW 10th Ave, Room 246
Portland, OR 97201




More information about the R-help mailing list