The columns containing relative abundance taxa does not sum to 1 in R but the same data does in excel

75 Views Asked by At

I have a data file with 95 columns and many rows (over 14000). I have calculated the relative abundance and now want to verify that sum of each column is 1. But it does not work on R. I tried to test if sum of each column is real 1 (or near 1) and did it manually in excel and it did, the sum of columns was 1. I tried to change the tolerance if the issue is because of rounding numbers, but it was not. here is my code:

tolerance <- 1e-10
sums_relative_abundance <- colSums(relative_abundances)
all(abs(sums_relative_abundance - 1.0) < tolerance)

my data has 95 columns.

head(relative_abundances)
 

     X1003           X1004           X1027           X1049
1   2.334938e-03    8.367276e-04    8.928571e-03    3.050125e-02    
2   2.880184e-04    1.224950e-04    6.647746e-04    3.065996e-04    
3   1.457391e-03    7.153990e-04    1.106922e-03    5.461621e-04    
4   5.188696e-05    3.413513e-05    8.658196e-05    1.800099e-05    
5   2.164549e-05    9.000495e-06    1.882176e-05    9.798542e-06    
6   1.882176e-05    1.959708e-05    5.381118e-05    1.104796e-04    

dput(head(sums_relative_abundance))
c(X1003 = 0.523067970544805, X1004 = 0.462073648305777, X1027 = 0.751016736292847, 
X1049 = 1.14795999147871, X1053 = 0.892912676398911, X1058 = 1.03526073508692
)
0

There are 0 best solutions below