[R] Vector of Vectors

Shawn Garbett Shawn.P.Garbett at Vanderbilt.Edu
Wed Apr 1 18:58:00 CEST 2009


I have a matrix of data. I need to scan the matrix and find every  
sequence from maxima to maxima across a row. I can write a loop to do  
this easily. Problem is, I can't figure out how to store the results.  
Each result is a vector of widely varying lengths. Ideally I'd like a  
vector of these, i.e. a vector of vectors, so I can quickly iterate  
through them and compute correlation coefficients.

Here's a transcript of my fuddling to date:

 > x <- c(1,2,3)
 > y <- c(4,5)
 > v <- list("1"=x, "2"=y)
 > unlist(v["1"])
11 12 13
  1  2  3
 > unlist(v["1"])[1]
11
  1
 > unlist(v["1"])[2]
12
  2
 > unlist(v["1"])[3]
13
  3
 > unlist(v["2"])[3]
<NA>
   NA
 > unlist(v["2"])[2]
22
  5
 > v <- c(x,y)
 > v
[1] 1 2 3 4 5
 > v <- vector()
 > v <- merge(v, x)
 > v
      [,1] [,2]
attr(,"row.names")
integer(0)
 > v[1]
[1] NA
 >

As you can see, vectors aren't very cooperative and lists are  
downright baffling to me.

Shawn Garbett <shawn.p.garbett at vanderbilt.edu>
Vanderbilt Cancer Biology
220 Pierce Ave, PRB 715AA
Nashville, TN 37232
Office: 615.936.1975
Cell: 615.397.8737




More information about the R-help mailing list