# creating a summary table with specific formula

Hello all,
I'm new to Rstudio and the community. I've been learning coding watching YouTube videos, and for the most part I can figure out most of my needs. Being said that, I'm having a hard time trying to find a way of subtracting the 10th value upstream of the max value for a series.

In summary I have a line ROI across a cell junction. I'm measuring intensity perpendicular to the junction so the values look like a bell shape (see attached picture). these values range from 0-3 um and my max intensity lies ~ 1.5 um but it is not always perfect, can try slightly between junctions.

I'm interested in coding to have a summarized dataframe (dataframe2) extracting max intensity value for each ROI and a new value "x" that represents: "max value - the 10th value up from the max value" (each data point spans almost 1/10th of a micron so it will be around the .5um mark in the x axis, or 1um from the max intensity point).

so far I've wrote this:

dataframe2 <- dataframe %>%
ddply((EXP ~ ROI ~ MUT), summarize,
max_intensity = max(Value),
x= ((max(Value) - first(Value)))

which was a nice work around given that the first value is position 15th up from the max intensity (roughly). But I want to be more precise with my math so I want to be exactly 1 um from the max intensity.
I know there should be an easy way to index for the 10th cell up from the max. I tried which.max(Value)-10 but didnt work.

x=((max(Value) - (which.max(Value)-10)). *and it didnt work

Thanks in advance, any suggestions are welcomed thanks See the FAQ: How to do a minimal reproducible example `reprex` for beginners for a more directed answer.

``````vec <- c(42, 3, 96, 83, 6, 24, 52, 5, 86, 47, 78, 67, 98, 23, 88, 44, 32, 75, 60, 41, 55, 21, 68, 93, 38, 22, 61, 37, 19, 13, 56, 15, 73, 74, 12, 97, 40, 62, 79, 58, 59, 18, 20, 51, 81, 48, 17, 80, 84, 27)

vec[which.max(vec) - 10]
#>  96
``````

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.