I have two matrices imported from csv files. They have the same number of rows and columns. I need a third matrix which would be the element-wise subtraction of the two matrices.
t1 <- read.csv("/matrix_1.csv", check.names = FALSE, sep = ",")
t2 <- read.csv("/matrix_2.csv", check.names = FALSE, sep = ",")
t1 looks like this:
Name,A,B,C,D,E
A,10,5,14,3,0
B,5,21,6,1,0
C,14,6,19,6,4
D,3,1,6,7,1
E,0,0,4,1,3
and t2 like this:
Name,A,B,C,D,E
A,4,5,4,3,0
B,5,2,6,1,0
C,1,6,1,6,4
D,3,1,1,7,1
E,0,0,3,1,2
Trying:
t3 = t1 - t2
doesn't work, it raises:
Warning message: In Ops.factor(left, right) : ‘-’ not meaningful for factors
Probably because t1 and t2 contain strings headers for rows and columns (which are important for the rest of the operations).
How would I go about subtracting two matrices without taking into account the strings for each row and column?