[datatable-help] Matrix multiplication

akang adi2827 at gmail.com
Mon Mar 7 04:08:43 CET 2016


I have two files. Row id in File1 matches the column id in file2 (starting
from column7 )except the last 2 characters. File1 has 50 rows and File 2 has
56 columns. If the id matches I want to multiply the value in column3 of
File1 to the entire column in File2. and in the final output print only
Column2 and column7 onwards from file2. Any awk or R suggestions?
File1
P1  A   -0.468018   -3.49806    
P2  A   0.0903727   0.675471    
P3  C   0.441187    3.29752 
P4  C   0.240075    1.79437 


File2
ID1 ID2 ID3 ID4 ID5 ID6 P1_A P2_A P3_C........
0 A01 0 0 0 0 0 2 1 
0 A04 0 0 0 0 1 1 0 
0 E05 0 0 0 0 0 1 2 
0 G06 0 0 0 0 2 0 2 

Output(I need the multiplication values to be printed to the final output
file. Like in row2 & column2 of output file 0*-0.468018=0, so i want 0 to be
printed and so on.)
ID2  P1 P2 P3........
A01  0*-0.468018 2*0.0903727 ....
A04  1*-0.468018 1*0.0903727...
E05  0*-0.468018 1*0.0903727....
G06  2*-0.468018 0*0.0903727...


This is what i have tried in R. But it doesn't give the desired output.I'll
appreciate any help. TIA! 

Code:
for(i in 1:nrow(file2)){
file2[i,2:6]<-file2[,2:6]*file1[match(substr(colnames(file2)[i],1,2),file1[,1]),3]
}
file2




--
View this message in context: http://r.789695.n4.nabble.com/Matrix-multiplication-tp4718309.html
Sent from the datatable-help mailing list archive at Nabble.com.


More information about the datatable-help mailing list