I have three excel files, Book1, Book2, Book3, with me. Each one of them consists of 4 rows and 5 columns. And each cell contains a numeric value of an observation. Now I have a 3 tuple, (1, 2, 1) and I want to compare the numeric values of each cell of Book1 with 1st tuple (1) and of Book2 with 2nd tuple (2) and similarly Book3 with 3rd tuple (1). Now, whenever the corresponding cells of these excel files match with this tuple, I want to print 1 otherwise 0. That is, say my (1,2) cell in Book1 contains 1, in Book2 the cell (1,2) contains 2 and in (1,2) cell of Book3 we have 1, then I want to print 1 else 0.
So this is the program I wrote :
library(openxlsx)
Book1 = read.xlsx("D:/Python/Book1.xlsx" , colNames = FALSE)
Book2 = read.xlsx("D:/Python/Book2.xlsx" , colNames = FALSE)
Book3 = read.xlsx("D:/Python/Book3.xlsx" , colNames = FALSE)
for (i in range(1,4)) {
for (j in range(1,5)) {
if(Book1[i,j]==1 & Book2[i,j]==2 & Book3[i,j]==1)
print(1)
else
print(0)
}
}
But the output I am getting is not what I expected.
1
0
0
1
Just these 4 numbers. I thought my loop would would give me a total of 20 values of 1's and 0's. But there seems to be some problem with the program which I can't detect. Can someone please help me with this?
Also, if instead of 4 rows and 5 columns, I have a very large number of rows and columns, say 10000 each, then will this format of the program work or some other methodology is required?
Aucun commentaire:
Enregistrer un commentaire