Making a list of adjacencies
0
0
Entering edit mode
7.5 years ago
zizigolu ★ 4.4k

Hi,

I have two adjacency matrices like so;

    > head(a[,1:4])

      0.000000000 0.001287944 0.0009840186 0.001331908
     0.009028600 0.000000000 0.0454970255 0.086481054
     0.009351082 0.100214642 0.0000000000 0.084016084
    0.012369094 0.101991920 0.1127636027 0.000000000
     0.005782680 0.069187046 0.0926961992 0.057618739
     0.010028177 0.085836197 0.0683108590 0.115312672
    > 

> head(b[,1:4])

  0.000000000 0.003395823 0.003414964 0.003790899
 0.019616886 0.000000000 0.098057502 0.096651371
 0.021880933 0.088377908 0.000000000 0.084118997
 0.020337222 0.105928503 0.088049864 0.000000000
 0.013806135 0.072800378 0.094627229 0.085720740
 0.009753766 0.070203073 0.089240739 0.099314366
>

I want to make a list of them

But when i feed my list to a tensor gives error

    A=list(a,b)
    library(rTensor)
    G <- as.tensor(A)
cpG <- cp(G,num_components = 4)
    Error in .is_zero_tensor(tnsr) : 
      (list) object cannot be coerced to type 'double'
R Factorization • 1.3k views
ADD COMMENT
0
Entering edit mode

As @Jean-Karim Heriche suggested in his tutorial, I firstly wrote my adjacency as a file in a directory, I then ran his code so

Get list of adjacency matrices

Each matrix is in a csv file

fileList <- dir(path=dataDir,pattern = ".csv")

Read all adjacency matrices into an array

A <- array(as.numeric(NA),dim=c(26,26,2)) # There are 2 matrices of size 26 x 26

for (i in 1:length(fileList)){

    A[,,i] <- as.matrix(read.delim(file.path(dataDir,fileList[i]), sep = ';', header=TRUE, row.names=1))

}
ADD REPLY

Login before adding your answer.

Traffic: 3378 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6