The goal here is to automate a data processing pipeline, where I can read in a .csv file and run a script and output the processed file, ready for data plotting. All I'm doing is applying some operations to a few columns, but automating one step is unclear to me:
I need to divide values in one column by those in another, but before division I need to subtract a value from a specific cell. However in each different .csv that specific cell location will change, so I can't simply extract a column/row cell as a variable and use that. As an example data frame:
df<-
sampleid t1 t2
a1 4 15
a2 3 18
a3 7 30
b1 6 17
blank 1 5
The function would then be
df <- df %>% mutate(ri=(t1-1)/(t2-1))
Where the "1" subtracted from t1 and t2 comes from the "blank" row "t1" value. I'd like to create a variable of the value of that cell, to substitute into that equation (occasionally it's something other than 1). The specific row in the csv/data frame will change based on the total sample number, so I can't choose a fixed cell every time.
Ideally it would just be
df <- df %>% mutate(ri=(t1-x)/(t2-x))
Where "x" was assigned to that blank t1 value from the data frame.
Any thoughts on a nice way to do this? Thank you.