I'm coding product unit cost.
Is there any short version of round values while I aggregate my data?
#Product unit cost
Summary.Cost <- aggregate(Toplam.TL, list(Product.Name = BOM$Product.Name), sum)
Total.Cost <- round(Summary.Cost[2],2)
Summary.Cost <- cbind(Summary.Cost[1],Total.Cost)
colnames(Summary.Cost) <- c("Product Name", "Total (TL)")
Summary.Cost
write.xlsx(Summary.Cost, "attempt.xlsx", "Sheet 1",row.names = F)
Output
Product Name Total(TL)
1 A 3.91
2 B 4.00
3 C 3.92
4 D 4.28
5 E 82.65
6 F 3.95
7 G 21.35
8 H 14.64
CodePudding user response:
Please share your data using dput()
. Example combining round and sum in aggregation below
Summary.Cost <- aggregate(Toplam.TL, list(Product.Name = BOM$Product.Name), FUN = function(x) round(sum(x), 2))