Tou Mou
Tou Mou

Reputation: 1274

How to transform this data structure to a matrix?

I have the following function:

tANN_matrix<-function(LSH_result_tables,t){
 i=dim(LSH_result_tables)
 v=i[2]
 tann_matr=matrix(data=NA,nrow=i[2],ncol=t)
 tann_matr=lapply(1:v, function(x) rbind(tann(x,LSH_result_tables,t)))
 tann_matr=matrix(unlist(tann_matr),ncol=t,byrow = TRUE)
 return(tann_matr) }

The function works well , it allows to calculate the ( t-approximate nearest neighbors for a vector within a database).

LSH_result_tables: represent a 3 dimensional hash table (e.g. the res variable)

res variable

The execution of the function tANN_matrix gives the following result:

tANN_matrix output

Question: How to transform this output to a matrix ?


NB: The function tann(x, LSH_result_tables ,t) in rbind is defined as following:

tann<-function(point_index,LSH_result_tables,t){
  integer_var=dim(LSH_result_tables)[3]
  a=LSH_result_tables
  nearests=c()
  foreach(i=1:integer_var) %do%

    if(!(all(a[,,i] == a[,1,i]))){
      nearests=unique(append(nearests,equal_cols(a[,,i],point_index,t)))
      while (length(nearests) >= t ) break
    }
       return(nearests[1:t])  
} 

Upvotes: 1

Views: 52

Answers (1)

Tou Mou
Tou Mou

Reputation: 1274

I found the solution , i should transform a list to a matrix so i need to use :

install.packages("sprof", repos="http://R-Forge.R-project.org")
library("sprof", lib.loc="~/R/win-library/3.5")

list_1 <- list(v1=7:9,v2=15, v3=11:15)
matrix_1=list.as.matrix(list_1)

Upvotes: 1

Related Questions