通过矩阵列表 - 知道当前元素的索引

时间:2013-07-27 20:15:28

标签: r

我是R的新手,我发现一个矢量操作令人沮丧:

我只想在使用sapply时知道列表的当前元素的索引,比方说:打印索引,但我的所有试验都不起作用,例如:

> test <- sapply(my.list.of.matrices, 
                 function(x) print(which(my.list.of.matrices == x)))

Error in which(my.list.of.matrices == x) : 
  (list) object cannot be coerced to type 'logical'
In addition: Warning message:
  In my.list.of.matrices == x :
  longer object length is not a multiple of shorter object length

1 个答案:

答案 0 :(得分:0)

除非传递索引向量,否则这是不可能的。 sapply和lapply只是传递元素。在那种情况下,它变成了伪装的循环。