I am working with a dataframe (n = 13,000) containing financial data in dollar amounts, stored as numeric. There are 5 columns (C1 - C5) containing dollar amounts and I am trying to create a new column (C6) that is a based off a calculation of 4 others. I am using the following code:
df$C6 <- C1 + C2 + C3 - C4
However, when looking at the the output I notice R is storing it in scientific notation. Furthermore, when I covert it using format
I notice the values are slightly off. For example what should be 7.46 ends up as 7.4599999999999999644729.
I decided to investigate further and I noticed that only specific rows are causing this to happen and R is forcing all other rows into scientific notation as a result.
Values for one such row are: C1 = 6.47 C2 = 1.00 C3 = 0.00 C4 = 0.00. This is resulting in C6 = 7.4599999999999999644729 after converting the scientific notation into decimal using format.
Any advice would be appreciated.