I'm not sure how to verbalize this question correctly. But this has been bothering me for quite some time. Is R by any chance inflate the actual figures taken from excel to add precision? I work mostly by inputting data into excel workbook and doing calculations and data wrangling in R. Often time I find the total calculate in R does not tally with excel workbook figures.
Let's say in the excel workbook the input is only '34.691', in R, the input becomes '34.690999999999995'. The input is not from formulae, it is key in data as it is.
None of my input has more than 3 decimal places, yet once it's loaded into R and I check the values, a lot of it has tons of decimal places.
Consequently, when the input is sum up, the total is not exactly as that inside excel workbook.
Why is this happening? It's driving me crazy.
The code is not helpful, but as you can see I just load a lot of excel sheets as a list and view one of the dataframe from the list. I did not do any data transformation yet. It's as taken from excel.
library(tidyverse) #for data wrangling
library(readxl) #read excel file
# IMPORT DATA INTO R #######################################
#create function using readxl
read_excel_allsheets <- function(filename, tibble = FALSE) {
sheets <- readxl::excel_sheets(filename)
x <- lapply(sheets, function(X) readxl::read_excel(filename, sheet = X))
if(!tibble) x <- lapply(x, as.data.frame)
names(x) <- sheets
x
}
# Get all sheet using readxl package
mysheets <- read_excel_allsheets("bla bla.xlsx")
#view one df in the list
View(mysheets[["df1"]])
From that I can see data with tons of decimal places.