I am still new to R and need your help.
I have data in the form of an array, and I want to create a function that applies to a dataframe, to get 3 values from each row and use them as indices to get values from the list .
The function should take three values to identify the value in the array
select_value <- function(A, B, C) {
result <-array_main[A, B, C]
return (result)
}
and the array is
vector1 <- c(10, 20, 30, 40, 50, 60, 70, 80, 90)
vector2 <- c(100, 200, 300, 400, 500, 600, 700, 800, 900)
vector3 <- c(2, 4, 6, 8, 10, 12, 14, 16, 18)
array_main <- array(c(vector1, vector2, vector3), dim = c(3, 3, 3))
df <- data.frame (C1 = c(1, 2, 3), C2 = c(2, 1, 3), C3 = c(3, 2, 1))
So the function should take for example the first row from df [row values are (1,2,3)] and use that as indices for array_main to get array_main[1,2,3] and return the value 8, then the second row from df which is (2, 1, 2), so use that as indices for array_main to get array_main[2, 1, 2] and return the value 200, finally, the third row which is (3,3,1), so use that as indices for array_main to get array_main[3,3,1] and return the value 90 .
How can I get the values stored in the (result) variable as a vector?
Thank you so much for your help