What i want to have is a matrix in which each element is a list itself. See the following example:
1 2 3
1 1,2,4 1,2 1
2 Null 3,4,5,6 1,3
I saw this post, and tried the following but got an error :
b <- array()
b[j, i, ] <- A[i]
where A is a vector itself. The error was:
Error in b[j, i, ] <- A[i] : incorrect number of subscripts
How should I define and access each element of the matrix and each element of the contained lists?
Update1 :
b<-matrix(list(),nrow = length(d), ncol =length(c))
Error in b[j, i] <- A[i] : replacement has length zero
I want to specify that each element is a list and then try to fill it with various list with different length from zero to n.
Update2 :
running what @BondedDust commented :
b<-matrix(rep(list(),(c*d)),,nrow = length(d), ncol =length(c))
Erorr in b[[j*nrow(b)+i]] <- A[i] : attempt to select less than one element
A :
A[1]<-c(3) F[[1]]<-numeric(0) E[[1]]<-numeric(0)
A[2]<-c(1) F[2]<-c(1) E[2]<-c(1)
A[3]<-c(1) F[3]<-c(2) E[[3]]<-numeric(0)
A[[4]]<-c(1,3) F[[4]]<-numeric(0) E[[4]]<-numeric(0)
A[5]<-c(4) F[5]<-c(4) E[5]<-c(4)
A :values of row 1 , F:row 2 and E :row 3. ( 5 column )
this data is not in this form and is not stored any where,they are the output of another function (there is function in the place of A[i]
).the data just show what dose A
look likes reproducibly and therefore shows the position in the matrix and gives back the error
in update2.A[4]
is the element of column 4 row 2.