I am working with CSV file format data in R. There are 315 rows in a column called itemsDispensed. I want to calculate the total sum of these numbers.
I have tried to do sum(as.numeric(as.character(....))) in R however the result I get is different from the sum that I have got while doing in excel.
The code below shows the first 20 rows:
head(select2014Chap6Sec1[ ,4], n = 20)
[1] 11.615 0.001 0.023 0.026 56.101 7.127 8.572 0.004 0.001 45.98 225.525 0.526
[13] 119.999 0.004 0.522 4.781 31.473 0.001 2.338 0.712
6999 Levels: 0 0.001 0.002 0.003 0.004 0.005 0.006 0.007 0.008 0.009 0.01 0.011 0.012 0.013 ... 999.958
The method I am using shows below:
> sum(select2014Chap6Sec1[ ,4])
[1] 778211
The error for sum(as.numeric(as.character(....))) shows below with NA value:
> sum(as.numeric(as.character(testFactorCol4)))
[1] NA
Warning message:
NAs introduced by coercion
I can provide all the data if you want using dput method. Thank you