I have a data frame, consisting of thousands of rows and 27 columns. What I want is to create a new simplified one, where every 3 consecutive columns are substituted by their row means.
This is a simple example to clarify:
df = data.frame(x1=c(1,2,3), x2=c(1,1,1), x3=c(4,5,3), x4=c(0,0,0), x5=c(1,2,1),
x6=c(2,4,5), x7=c(3,3,9), x8=c(0,0,1), x9=c(1,1,0))
I would like to obtain a new data frame with 3 rows and 3 columns, where the 1st column would be the mean of x1
, x2
, and x3
, etc.
Does anyone know how can this be done, in base R if possible?
Thanks in advance for any help!