按索引对切片R数组

Mit*_*tch 2 arrays r slice

我在R中有一个包含3列的数组,如下所示:

>x
[,1]     [,2] [,3]
V1 7.803550 0.000000    0
V2 7.842899 0.000000    0
V3 7.310273 0.000000    0
V4 7.230438 0.000000    0
V5 6.582147 1.097024    0
V6 9.364152 0.000000    0
Run Code Online (Sandbox Code Playgroud)

对于我的数组切片,我希望每行有不同的列,以便我想要的索引是:

rows<-1:6
cols<-c(1,1,1,2,3,1)
Run Code Online (Sandbox Code Playgroud)

当我尝试在R中获取适当的数组切片时,而不是获取具有适当值的向量,

> t
      V1       V2       V3       V4       V5       V6 
7.803550 7.842899 7.310273 0.000000 0.000000 9.364152 
Run Code Online (Sandbox Code Playgroud)

我得到一个6x6的输出矩阵,其中为所有选定的行打印出给定的列

> t
       [,1]     [,2]     [,3]     [,4] [,5]     [,6]
V1 7.803550 7.803550 7.803550 0.000000    0 7.803550
V2 7.842899 7.842899 7.842899 0.000000    0 7.842899
V3 7.310273 7.310273 7.310273 0.000000    0 7.310273
V4 7.230438 7.230438 7.230438 0.000000    0 7.230438
V5 6.582147 6.582147 6.582147 1.097024    0 6.582147
V6 9.364152 9.364152 9.364152 0.000000    0 9.364152
Run Code Online (Sandbox Code Playgroud)

如何在没有for循环的向量中获得所需的索引对?

根据大卫的建议,我希望能够运作的代码

t<-x[rows,cols]
Run Code Online (Sandbox Code Playgroud)

42-*_*42- 9

怎么样:

x[cbind(rows, cols)]
Run Code Online (Sandbox Code Playgroud)

读入?"["为什么这应该工作.(我的赔率比罗宾逊的博彩策略更快.)