[R] variable three dimensional array

Jim Lemon jim at bitwrit.com.au
Wed Jan 6 10:54:28 CET 2010


On 01/06/2010 06:04 AM, Fahim Md wrote:
> I am using R for my bioinformatics research. I am dealing with a graph in
> which I need to find all possible path. I was looking for some package that
> solve my purpose
> but all in vain. There are available algorithms but most of them find
> shortest path that ignore other paths So I decided to write my own from
> scratch.
>
>
> I need to create a two dimensional matrix of size nXn.
> The element of each entry may contain (node,edge) pair in the form of
> bit-vector.
>
> eg. (mat is the matrix)
> mat[1,1] = NULL
> mat[1,2] = {10000, 10000100}      #first entry is node vector and second
> entry is edge vector
> mat[1,3] = {{01000, 01001000}, {00100, 01000010}} #Here there are two
> node-edge pair. There can be more also, so it is variable.
>
> In other sense it can be said that, the matrix is a 3-d matrix with a
> variable third dimension.
>
> I tried the problem with list but I was partially succesful.
>    
Hi Fahim,
I'm not sure that I understand exactly what you are trying to do, but it 
looks to me like a list would be the way to go. Each element of the list 
can contain variable numbers of elements, so:

nep.list<-list(NULL,c(10000, 10000100),
  list(c(01000, 01001000),c(00100,01000010)))

nep.list
[[1]]
NULL

[[2]]
[1]    10000 10000100

[[3]]
[[3]][[1]]
[1]    1000 1001000

[[3]][[2]]
[1]     100 1000010

The function listBuilder in the crank package may give you some hints on 
how to automate the process of building such a list.

Jim



More information about the R-help mailing list