Let's say I have a dataset that looks as follows:
subvalues <- c(1:10)
df <- data.frame(x = rpois(40,2), y = rpois(40,2), z = rpois(40,2))
I want to take the value from the first cell of subvalues and subtract that from every cell in x, then the 2nd cell of subvalues and subtract it from every cell in z, etc. - Thereby generating a new dataframe where every row in x and z are new values (original value minus value from selected cell of subvalues)
note that my actual dataset is thousands of rows and columns, so brute-forcing it is not an option.
From what I have gathered I need to use the mutate_at function but I have no idea how to create a function that selects first the first row of subvalues, then the 2nd, etc.
Any help is much appreciated