Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to round decimal values on aggregate function?

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

       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

>Solution :

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))
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading