[R] data manipulation: getting mean value every 5 rows

Federico Calboli f.calboli at ucl.ac.uk
Mon Jul 28 23:47:16 CEST 2003


Dear All,

I would like to ask you how to accomplish a little tricky data
manipulation. I have a large dataset, looking something like:

temp	line	cage	number
18	18	1	6678.63
18	18	1	7774.458
18	18	1	7845.902
18	18	1	9483.578
18	18	1	8983.555
18	18	1	9181.052
18	18	1	9458.696
18	18	1	8138.616
18	18	1	7981.994
18	18	1	7556.491
18	18	1	7672.137
18	18	1	6607.776
18	18	1	8383.65
18	18	1	7129.852
18	18	1	8536.667
18	18	2	8287.8
18	18	2	7924.47
18	18	2	7928.474
18	18	2	7363.157
18	18	2	7952.593
.....

I would like to create a dataframe where I get the mean values, 5 rows at a
time, of columns "number", while keeping the value in the other columns
fixed to the vaules found in the first of the 5 rows (or whatever, it's the
same for the 5 rows) so that the above would be "shrunk" to:

temp	line	cage	number	
18	18	1	8153.2246
18	18	1	8463.3698
18	18	1	7666.0164
18	18	2	7891.2988
 
Any hints?

Regards,

Federico Calboli

=========================

Federico C.F. Calboli

Department of Biology
University College London
Room 327
Darwin Building
Gower Street
London
WClE 6BT

Tel: (+44) 020 7679 4395 
Fax (+44) 020 7679 7096
f.calboli at ucl.ac.uk




More information about the R-help mailing list