0

dput(high = [28,27,25,26,27,28,29])

Here is my data: enter image description here

For the column high: I need to take the first seven values and calculate the max then for the next seven values and so on

my code:


diffThigh <-0
m=1

 for (i in seq(1, 871, by=6)){
   print(i) 
   
   diffThigh[m] <-  (max(Dataset_1$high[i:i+6]))
   
    i=i+1          
   
     m=m+1  
     }

diffThigh

The array I get has wrong values

  • 1
    Please [make this question reproducible](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) by including example data in a plain text format - for example the output from `dput(yourdata)`. We cannot copy/paste data from images. – neilfws Mar 23 '21 at 03:01

1 Answers1

0

Try with tapply to get max of every 7 values.

result <- tapply(Dataset_1$high, ceiling(seq(nrow(Dataset_1))/7), max, na.rm = TRUE)
Ronak Shah
  • 377,200
  • 20
  • 156
  • 213