Here’s a row-wise iteration problem that I’ve been trying to solve with purrr::pmap, but no luck.
I start with a table of raw scores:
rawscore_table <- data.frame(rawscore = 10:14, SS1 = NA, SS2 = NA)
rawscore SS1 SS2
1 10 NA NA
2 11 NA NA
3 12 NA NA
4 13 NA NA
5 14 NA NA
There are two empty columns, SS1 and SS2, whose values I want to obtain by applying a function to each row:
SS1 = rawscore + x + y
SS2 = rawscore + x + y
The values of x
and y
are found in a lookup table:
lookup_table <- data.frame(SS = c('SS1', 'SS2'), x = 1:2, y = 3:4)
SS x y
1 SS1 1 3
2 SS2 2 4
The solution I’m looking for will calculate the values of column rawscore_table$SS1
by finding the values of x
and y
in the SS1
row of lookup_table
, and it will calculate the values of column rawscore_table$SS2
by finding the values of x
and y
in the SS2
row of lookup_table
.
So the code has to refer to the name of the column in rawscore_table
in order to pluck values from the corresponding row of lookup_table
.
The desired output looks like this:
rawscore SS1 SS2
1 10 14 16
2 11 15 17
3 12 16 18
4 13 17 19
5 14 18 20
Thanks in advance for any help!