当前位置: 动力学知识库 > 问答 > 编程问答 >

R operation without for loop

问题描述:

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.

网友答案:

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)]
分享给朋友:
您可能感兴趣的文章:
随机阅读: