Vector base Cosine Similarity for two Matrices -- R in UNIX


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Vector base Cosine Similarity for two Matrices -- R in UNIX
# 8  
Old 02-22-2013
my data looks like this
data01.csv
Code:
3 ,5 ,0
0 ,0 ,0 
0 ,0 ,0 
2 ,5 ,0
0 ,0 ,0

data02.csv
Code:
4 ,3.5 ,0.25
1 ,3 ,0
0 ,0 ,0 
3 ,4.33333 ,0.888889
0 ,0 ,0

no header or anything else
I have realize some more mistakes and corrected it (n=1)
problem is in reading each line to a vector Smilie
Code:
con  <- file('data01.csv', open="r")
con2 <- file('data02.csv', open="r")
current.line<- 1
a<- vector();
b<- vector();
while (length(data01 <- readLines(con, n = 1, warn = FALSE)) > 0) {
	data02 <- readLines(con2, n = 1, warn = FALSE)
	a[[current.line]]<- as.vector(strsplit(data01, split=","))
	b[[current.line]]<- as.vector(strsplit(data02, split=","))
	test<- cosine (a[[current.line]], b[[current.line]])
	write.csv(test, file="test.csv")
	current.line <- current.line+ 1
  } 
close(con)
close(con2)

still getting the same error
# 9  
Old 02-22-2013
I been away for a while, so help me. Three values defines a line vector in 2+D space? Is the other end assumed to be the 3d origin, or the length infinite? Not sure why a and be need to be stored in an array. Is it as.vector or cosine that is creating the error? Maybe the spaces, or the character form of the numbers (no atof() call for ascii to float)?
# 10  
Old 02-22-2013
the 3 columns are frequencies for different values in a few documents
I have tired to remove the middle look and tried to create a loop to read the first line into lines of vectors only ... which it didn't ... so assuming the problem is with reading lines of the files into vectors ...
# 11  
Old 02-22-2013
Slip in some debug code to display the vector valuess and parent text.
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Split a content in a file with specific interval base on the delimited values using UNIX command

Hi All, we have a requirement to split a content in a text file every 5 rows and write in a new file . conditions: if 5th line falls between center of the statement . it should look upto after ";" files are below format: 1 UPDATE TABLE TEST1 SET VALUE ='AFDASDFAS' 2 WHERE... (3 Replies)
Discussion started by: KK230689
3 Replies

2. UNIX for Dummies Questions & Answers

Multiplication of two matrices

Hi there! I have two files like below File1(with a header, ~1000 rows, ~50 columns) ID1 ID2 ID3 ID4 ID5 MI1_A MI1_H MI2_A MI2_H 0 1 0 0 0 1 0 2 1 0 2 0 0 0 2 1 0 1 File2 (without a header, ~50 rows) MI1 A 0.4 3.1 MI2 B -0.2 0.1 Output ID2 M1_A M2_A 1 1*0.4 2*-0.2 2 2*0.4 0*-0.2 ... (22 Replies)
Discussion started by: Akang
22 Replies

3. UNIX for Dummies Questions & Answers

Merge matrices

Hello all, I have square matrices that look like the following, I want to merge these matrices together, and add the file names as headers. This is a simple example with two variables, actually I have ~1500 variables and 10 files. The order of variables in the matrices are consistent. Please... (2 Replies)
Discussion started by: senhia83
2 Replies

4. UNIX for Dummies Questions & Answers

Importing R cosine similarity to UNIX?

I really need help in this :( I have a file and would like to calculate the cosine similarity of the values in it... For now I do use R which has an easy function for doing so test <- as.matrix(read.csv(file="file.csv", sep=",", header=FALSE)) result<- cosine(t(test)) I am using unix of... (3 Replies)
Discussion started by: A-V
3 Replies

5. Shell Programming and Scripting

Help with merge data based on similarity

Input_file data1 USA 100 ASE data3 UK 20 GWQR data4 Brazil 40 QWE data2 Scotland 60 THWE data5 USA 40 QWERR Reference_file USA 12312 34532 1324 Brazil 23321 231 3421 Scotland 342 34235 UK 231 141 England... (1 Reply)
Discussion started by: patrick87
1 Replies

6. UNIX for Dummies Questions & Answers

Unix commands in Base SAS programming

hi all, iam using unix command in the basesas programming. i need to delete one folder which is dynamically creating when SAS script runs. rm -rf " dynamic foldername" iam not able to delete the folder it is saying rm: cannot remove directory `test_lin_prod_06_20091211_0516':... (2 Replies)
Discussion started by: bbc17484
2 Replies

7. UNIX for Advanced & Expert Users

Configure SCO Unix to print on windows base XP printer

Hi, I have done this year ago, and now I need to do it again, but did not remember how I do it. I have a slip printer on a windows xp workstation and i need to print from SCO unix application to that printer. I try to create a remote printer but the only option available is unix, the other to... (0 Replies)
Discussion started by: comsiconsa
0 Replies

8. UNIX for Dummies Questions & Answers

recommendation please. Unix base ftp program

in win32 platform, i can easily find some GUI based ftp application like cuteFtp, WsFtp and etc which provides GUI + resuming download. pls recommend me some similar application which runs on Sun Solaris sparc 8. hopefully it is free. thank you very much. (1 Reply)
Discussion started by: champion
1 Replies
Login or Register to Ask a Question