Hi
I have 30 sheets from an excel file which I would like to join into one data frame using tidyverse joining functions. The first three works perfectly well however when I make additional sheet/dataframe it throws this error which I am unable to troubleshoot.
Error in left_join():
! suffix must be a character vector of length 2, not a <data.frame> object of length
11.
I am not sure if I need to define suffix argument in my left_join function and how that should be.
Basically this is how my code reads:
invent <- inv %>%
left_join(
biochem,
haematology,
roller,
by = c("_index" = "_parent_index")
)
Not quite sure how exactly did you implement the "The first three works perfectly"-part, but left_join() takes only 2 input frames as 2 first arguments, x and y:
left_join(x, y, by = NULL, copy = FALSE, suffix = c(".x", ".y"), ..., keep = NULL)
In your call there are 4 positional arguments and one by name, so it is evaluated as:
left_join(
x = inv,
y = biochem,
by = c("_index" = "_parent_index"),
copy = haematology,
suffix = roller
)
with roller set as suffix arg.
You can get away without an error/warning when using non-logical copy, which is probably what happened when you tried to join 3 frames (though result is probably not what you might expect), but not with a suffix that's not a vector of length 2.
If you have a list of dataframes, you could use Reduce() or purrr::reduce() for this, should look something like (untested):
all_30_sheets_as_a_list_of_dataframes |>
purrr::reduce(dplyr::left_join, by = c("_index" = "_parent_index"))
A complete reprex would make this easier to evaluate, but I agree with margusl. You are likely giving a dataframe ("roller") to the suffix argument.
If you have 30 sheets from an excel file, do these 30 sheets hold values from variables representing a set of observations (do the sheets share an identifier like an "id" column)?
If you don't have a common column to join on, you might have better luck with bind_rows if you're just trying to get all of the data into a single dataframe to play around with. You can pretty easily do this with a for loop or purrr:map() or lapply().
Good luck!
This topic was automatically closed 90 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.