[R] Reformat a data frame

Michael Jerosch-Herold
Tue, 07 Nov 2006 23:01:00 -0000

You want to "reshape" from "wide" into "long"
format: see "help(reshape)".

For your example this should look something like

df2 <- reshape(df1,
varying=list(c("resist","thick","temp")),
direction="long",
                       v.names=c("Value"), timevar="Param",
                       idvar="ID",
times=c("resist","thick","temp"))

will give you roughly what you want - maybe not in the exact order as listed
below for df2, but you can "sort' then.

You are "merging" all value for three variables in the wide format,
into one variable ("Value") in the "long" format...

Try it, I did not test the above, but have done similar things before along
those lines.

Michael Jerosch-Herold

>>> "Thorsten Muehge" <MUEHGE@de.ibm.com> 11/07/06 1:10
AM >>>

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





	[[alternative HTML version deleted]]