Help with data iteration

Hello,

I want to create a script to center my data along a value.
My quantification took different vaues along distance and to compare between observations I need to center them on the maximum value and select max+/-n values.

For example:
INPUT OUTPUT
A B C A B C
10 5 5 10 5 25
20 5 5 20 20 35
50 20 25 50 60 70
30 60 35 30 50 50
15 50 70 15 40 30
10 40 50
5 20 30
5 10 10

I've created this part of the script that calculates the top and bottom numbers for each column but I don't know how to proceed to select them.

#for bucle to detect the position of the max values
out_pos<-vector("double",ncol(x1))
for(i in seq_along(x1)) {
out_pos[[i]]<-which.max(x1[[i]])
}
out_pos
str(out_pos)

#delineate tops and bottoms
top<-out_pos-50
bot<-out_pos+50
top
bot

Any help will be more than welcome! Thanks!

This example does not use your data. See the FAQ: How to do a minimal reproducible example reprex for beginners.

suppressPackageStartupMessages({
  library(dplyr)
})

dat <- data.frame(
  A =
    c(10, 20, 50, 30, 15),
  B =
    c(5, 5, 20, 60, 50),
  C =
    c(5, 5, 25, 35, 70),
  D =
    c(10, 20, 50, 30, 15),
  E =
    c(5, 20, 60, 50, 40),
  F =
    c(25, 35, 70, 50, 30))

dat %>% rowwise() %>% mutate(Max = max(c(A,B,C,D,E,F)))
#> # A tibble: 5 x 7
#> # Rowwise: 
#>       A     B     C     D     E     F   Max
#>   <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1    10     5     5    10     5    25    25
#> 2    20     5     5    20    20    35    35
#> 3    50    20    25    50    60    70    70
#> 4    30    60    35    30    50    50    60
#> 5    15    50    70    15    40    30    70

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.