[R] Data frame transpose
Thomas Lumley
tlumley at u.washington.edu
Mon Sep 29 20:27:09 CEST 2003
On Mon, 29 Sep 2003 Kang.Daiwen at epamail.epa.gov wrote:
>
> Hi All,
>
> I want to ask if there is a transpose function for data frame like the
> procedure of transpose in SAS? Because I want to partially transpose a
> data frame which contains 5 columns (siteid, date, time, obs, mod), what
> I want to do is to put time as the column variables along with siteid,
> and date, and put obs and mod in the row names. specifically to
I think reshape() does what you want
-thomas
> transpose a data frame:
>
> siteid date time obs mod
> A 7/8 01 2 5
> A 7/8 02 3 8
> A 7/8 03 5 8
> A 7/9 01 3 6
> A 7/9 02 5 8
> A 7/9 03 6 7
> ......
> B 7/8 01 4 7
> B 7/8 02 7 19
> B 7/8 03 4 9
> ......
>
> To
>
> siteid date name 01 02 03 ....
> A 7/8 obs 2 3 5
> A 7/8 mod 5 8 8
> A 7/9 obs 3 5 6
> A 7/9 mod 6 8 7
> .......
> B 7/8 obs 4 7 4
> B 7/8 mod 7 19 9
> ........
>
>
> Thank you very much!
>
> Dave
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
>
Thomas Lumley Assoc. Professor, Biostatistics
tlumley at u.washington.edu University of Washington, Seattle
More information about the R-help
mailing list