Hello all,
I am working with a large data frame. What I want is to simplify it by averaging rows that are closer by their row names. I will use a simple example:
r = 0.1 #Radius for averaging
data = data.frame(x1=c(0,60,0,76,7,0,11,0,87,0),
x2=c(4,33,0,116,0,0,48,0,63,0),
x3=c(15,40,0,124,0,0,51,0,83,0),
row.names=c("705.35","705.4","726.4","726.45","726.5","727.4",
"727.45","757.4","757.45","757.5"))
Defining a given radius r
, I would like to obtain a new data frame with rows averaged, grouping (in this example) rows c(1,2), c(3,4,5), c(6,7), c(8,9,10). I would like also the row names to be the mean of the previous ones.
Any help would be much appreciated, particularly using base R.
Thanks in advance for any help!