extract data from an array without using loop in R

Posted by Manolo on Stack Overflow See other posts from Stack Overflow or by Manolo
Published on 2012-10-14T21:21:37Z Indexed on 2012/10/14 21:37 UTC
Read the original article Hit count: 210

Filed under:
|
|

I have a vector v with row positions:

v<-c(10,3,100,50,...)

with those positions I want to extract elements of a matrix, having a column fixed, for example lets suppose my column number is 2, so I am doing:

data<-c()
data<-c(matrix[[v]][[2]])

matrix has the data in the following format:

[[34]]
      [1] "200_s_at" "4853"        "1910"        "3554"        "2658" 

So for example, I want to extract from the row 342 the value 1910 only, column 2, and do the same with the next rows

but I got an error when I want to do that, is it possible to do it directly? or should I have a loop that read one by one the positions in v and fill the data vector like:

#algorithm
for i<-1 to length(v)
    pos<-v[i]
    data[[i]]<-c(matriz[[pos]][[2]])
next i

Thanks

© Stack Overflow or respective owner

Related posts about r

    Related posts about vector