[R] Reformat a data frame
Dimitris Rizopoulos
dimitris.rizopoulos at med.kuleuven.be
Tue Nov 7 14:05:20 CET 2006
try the following
df2 <- reshape(df1[-1], idvar = "id", direction = "long",
timevar = "Param", times = c("resist", "thick", "temp"),
varying = list(c("resist", "thick", "temp")))
df2 <- df2[order(df2$id, df2$desc), ]
rownames(df2) <- 1:nrow(df2)
df2
I hope it helps.
Best,
Dimitris
----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven
Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
http://www.student.kuleuven.be/~m0390867/dimitris.htm
----- Original Message -----
From: "Thorsten Muehge" <MUEHGE at de.ibm.com>
To: <R-help at stat.math.ethz.ch>
Sent: Tuesday, November 07, 2006 10:10 AM
Subject: [R] Reformat a data frame
>
> Hello Experts,
> how do I reformat a data frame in the way described below:
>
>
> df1:
> ID desc resist thick temp
> 1 4711 100 5 20
> 2 4712 101 4 21
> 3 4711 99 3 19
> 4 4712 98 7 22
>
> TO
>
> df2:
> id desc Param Value
> 1 4711 resist 100
> 1 4711 Thick 5
> 1 4711 temp 20
> 2 4712 resist 101
> 2 4712 Thick 4
> 2 4712 temp 21
> 3 4711 resist 99
> 3 4711 thick 4
> 3 4711 temp 19
> 4 4712 resist 98
> 4 4712 thick 7
> 4 4712 temp 22
>
> Thanks a lot for your help.
> With best regards
> Thorsten
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm
More information about the R-help
mailing list