merging different sheet

I have an excel file with 13 sheets and I want to merge and join them by "PID".
( I'll use this cod to merge by PID >>> all <- left_join(sh1,sh2[,], by="PID") and then I want to save them I one file by using this code >>> save(all, file= "all.RData"))
i am using this code
sh1 <- read_excel("Dr.Mee.xlsx", sheet = "Maininfo")
sh2 <- read_excel("Dr.Mee.xlsx", sheet = "Anthropometric")
.
.
.
but for some of my sheet, it doesn't work and return this error >>>> There were 18 warnings (use warnings() to see them)
when I use this it returns two different codes. sometimes it returns this warning
1)

Warning messages:
1: In read_fun(path = enc2native(normalizePath(path)), sheet_i = sheet, ... :
Coercing text to numeric in H6129 / R6129C8: '90'
2: In read_fun(path = enc2native(normalizePath(path)), sheet_i = sheet, ... :
Coercing text to numeric in F7400 / R7400C6: '15'
3: In read_fun(path = enc2native(normalizePath(path)), sheet_i = sheet, ... :
Coercing text to numeric in C10818 / R10818C3: '84.5'
4: In read_fun(path = enc2native(normalizePath(path)), sheet_i = sheet, ... :
Coercing text to numeric in C13106 / R13106C3: '109'
5: In read_fun(path = enc2native(normalizePath(path)), sheet_i = sheet, ... :
Coercing text to numeric in F14855 / R14855C6: '15'
6: In read_fun(path = enc2native(normalizePath(path)), sheet_i = sheet, ... :
Coercing text to numeric in F14896 / R14896C6: '15'
7: In read_fun(path = enc2native(normalizePath(path)), sheet_i = sheet, ... :
Coercing text to numeric in F15258 / R15258C6: '16'
.
.
.
2)
and for some sheet, it returns this error >>>
Warning message:
In read_fun(path = enc2native(normalizePath(path)), sheet_i = sheet, :
Expecting numeric in F6889 / R6889C6: got 'NULL'

why I get this error?
how should I solve it?

That I think is because readxl will choose one type per column, based on the first 1,000 entries (argument guess_max). So, if there is an cell with '10 (note the quote mark which makes it text and not numeric) in the first 1,000 rows, readxl will make a character column in the data frame. Here, you have Excel files where the first 1,000 entries are numeric, so readxl expects the column to be double, but then the entry on row 6,129 is text, so readxl will force the conversion to be consistent with the first 1,000 entries, but warns you because it could not be what you want.

No idea, look in the cell F:6,889 of your Excel sheet, you might find the reason.


Side-note: this is unrelated and not absolutely necessary, but I recommend you work with lists, which will make your life easier later:

sheet_names <- c("Maininfo", "Anthropometric")

all_excel_content <- map(sheet_names,
                         function(current_sheet) read_excel("Dr.Mee.xlsx", sheet = current_sheet))

all <- reduce(all_excel_content, left_join, by = "PID")

Else you need to type every left_join() call manually.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.