Dear All,
I am facing a problem and I would be Thankful if you can help
Hope this is the right place to ask this question
I have two matrices of (row=10, col=3) and I want to get the cosine similarity between two lines (vectors) of each file --> the result should be (10,1) of cosine measures
I am using cosine function from Package(lsa) from R called in unix but I am facing problems with it
if these files had only one row per file I can calculate the cosine similarity as following
data01 <- c(t(read.table(file = "data01.csv", sep = ",", header=FALSE)))
data02 <- c(t(read.table(file = "data02.csv", sep = ",", header=FALSE)))
result <-cosine(data01,data02)
write.csv(result, "result.csv")
but facing problems reading lines of two files into Vectors to do the same
I have tried to write a code, it does not give any error but does not create anything and I dont know what I am doing wrong --- (new to R)
con <- file('data01.txt', open="r")
con2 <- file('data02.txt', open="r")
a <- list();
b <- list();
test <- list();
current.line01 <- 1
current.line02 <- 1
while (length(data01 <- readLines(con, n = 10, warn = FALSE)) > 0) {
while (length(data02 <- readLines(con2, n = 10, warn = FALSE)) > 0) {
a[[current.line01]]<- c(data01)
b[[current.line02]]<- c(data02)
test <-cosine(a[[current.line01]], b[[current.line02]])
write.table(test , "test.txt")
current.line01 <- current.line + 1
current.line02 <- current.line + 1
}
}
close(con)
close(con2)
can you please help me?
:(:(