I asked a question like this before but I decided to simplify my data format because I’m very new at R and didnt understand what was going on….here’s the link for the question How to handle more than multiple sets of data in R programming?
But I edited what my data should look like and decided to leave it like this..in this format…
X1.0 X X2.0 X.1
0.9 0.9 0.2 1.2
1.3 1.4 0.8 1.4
As you can see I have four columns of data, The real data I’m dealing with is up to 2000 data points…..Columns “X1.0” and “X2.0” refer “Time”…so what I want is the average of “X” and “X.1” every 100 seconds based on my 2 columns of time which are “X1.0” and “X2.0″…I can do it using this command
cuts <- cut(data$X1.0, breaks=seq(0, max(data$X1.0)+400, 400))
by(data$X, cuts, mean)
But this will only give me the average from one set of data….which is “X1.0” and “X”…..How will I do it so that I could get averages from more than one data set….I also want to stop having this kind of output
cuts: (0,400]
[1] 0.7
------------------------------------------------------------
cuts: (400,800]
[1] 0.805
Note that the output was done every 400 s….I really want a list of those cuts which are the averages at different intervals…please help……I just used data=read.delim("clipboard") to get my data into the program
It is a little bit confusing what output do you want to get.
First I change colnames but this is optional
Then I will use
avewhich is likebybut with better output. I am using a trick of a matrix to index column:Then I am using this matrix with
apply. Here the entire solution:EDIT correct the cut and simplify the code