Hi to all the community, I have the following DB:
ID Distance
M1_PRM 54,56
M1_PRM 4147,69
M1_PRM 1723,34
I use the following script to replace "," in "." in Distance as R doesn't like "," (and it works):
mysub<-function(x)(sub(",",".",x))
DB<-(apply(DB, 2,mysub))
DB<-data.frame(DB)
Then I need to convert DB$Distance as.numeric
because I need to use
tapply
in conjunction with sum, like:
apply(DB$Distance,ID,sum)
When I give
DB$Distance<-as.numeric(DB$Distance)
ID Distance
M1_PRM 54
M1_PRM 4147
M1_PRM 1723
It seems that R discard the decimal!!! Someone Know what is wrong? Thanks in advance!