I have two variables and I want to calculate the mean of the second variable into class according to the first.
The first variable is the time and take 100 values
The second variable is an index. I have divided the first variable into 4 classes (not equals). I want to calculate the mean of index for each class/group of time and then plot it according to the grouped time.
Important: I don’t want to use another package in R. Thanks in advance
time<-c(1:100)
index<-rnorm(100,0,1)
time_groups<-table(cut(time, seq(0,100,25)))
The cells of time are related with the cells of index.
How can I calculate the mean of index for each class?
The results should be:
group index
0-25 mean index
25-50 mean index
50-75 mean index
75-100 mean index