Reputation: 1
I have an index data frame which have index$row and index$col columns which indicate row and columns of X data frame.
index data frame
row col
375 1
376 1
379 1
380 1
381 1
460 4
461 4
462 4
463 4
I want to take the minimum values of each observation in X data frame, which is indicated by index data frame.
How can I do it without using a for loop? I need this because i have more than one index data frame and this takes very much time with for loop.
Upvotes: 0
Views: 91
Reputation: 886938
We can convert the 'index' to matrix
(assuming 'index' is data.frame
) and extract the values of the minimum values from the 'X' dataset using the row/column indexing provided by 'index'. The code is below
X{as.matrix(index)]
Upvotes: 1