[R] rearrange data: one line per subject, one column per condition

Dieter Vanderelst dieter_vanderelst at emailengine.org
Tue Nov 27 18:19:13 CET 2007


Dear R-list,

Is there a way to convert the typical long R data-format to a 1-line per subject format?

I have data formatted as:

Group	subj	condition	variable
1	1	1	746.36625
2	2	1	1076.152857
1	3	1	1076.152857
2	4	1	657.4263636
1	5	1	854.1266667
2	6	1	1191.676154
1	7	1	1028.175385
1	1	2	46.36625
2	2	2	76.152857
1	3	2	76.152857
2	4	2	57.4263636
1	5	2	54.1266667
2	6	2	191.676154
1	7	2	028.175385
...

Here, one line equals the value of one subjects  VARIABLE in function of the GROUP and the CONDITION.

However, I would like to rearrange the data so that the columns of my data equal the 2 conditions and the lines the subjects. This is something like:

subj	group	condition1	condition2
1	1	746.36625	46.36625
2	2	1076.152857	76.152857
...

I know its possible the other way around. But that's not what I need (this time).

Before anyone asks: Yes, I want to do some analysis on my data in SPSS, so I need the rearranged format.

Regards and Thanks,
Dieter 
------------------------------------------
Dieter Vanderelst

dieter _ vanderelst AT emailengine DOT org
d DOT vanderelst AT tue DOT nl

Eindhoven University of Technology
Faculty of Industrial Design
Designed Intelligence Group
Den Dolech 2
5612 AZ Eindhoven
The Netherlands
Tel +31 40 247 91 11



More information about the R-help mailing list