I've used tapply() a lot in R, but I have no idea why the order of magnitudes are suddenly converted after tapply() function is applied.
When I load the original CSV data, the data shows as follows.
Barcode Group Price
1002-01-23 A 10.23568975
1002-01-24 A 2356.25
1002-01-25 A 123.54897
1002-01-26 A 200.1548794
However, after I use R codes, the digits of Price are converted as follows.
Barcode Group Price mean
1002-01-23 A 10.23569 672.5474
1002-01-24 A 2356.25000 672.5474
1002-01-25 A 123.54897 672.5474
1002-01-26 A 200.15488 672.5474
I would like to have 672.5473847875(=(10.23568975+2356.25+123.54897+200.1548794)/4) as a result of mean. How could I solve the problem? Let me show you my R codes.
barcode <- read.csv("barcode.csv",header=T)
barcode$Group <- as.factor(barcode$Group)
barcode$Price <- as.numeric(barcode$Price)
test <- tapply(barcode$Price, barcode$Group, mean)
test1 <- data.frame(Group=names(test), mean=test)
barcode$mean <- test1$mean[match(barcode$Group, test1$Group)]
I really need your help. Thank you so much.