bind_rows is not working to append data frames with uneven variables

For appending two data frames with uneven variables, I get errors even when the common variables between the two data frames are of the same type. I understand and expect errors for different types for common variables. What are the retrictions for using bind_rows? As an alternative, I was able to create similar dummy variables in my second data frame and apply rbind successfully to append my two data frames of even variables.

Does anyone else have similar experience since appending uneven variables is an important data processing task?

Can you provide a reproducible example that demonstrates the error you're getting?

bind_rows() matches columns by names and something like dplyr::bind_rows(mtcars[, -1], mtcars[, -2]) is expected to work. Does it not in your case?

False Alarm! My code seems to be working this time. Glad to know that.

mtcars1a_mean <- mtcars %>%
group_by( cyl ) %>%
dplyr::summarize(wt = mean(wt, .1, na.rm = TRUE)) %>%
mutate(dtype='AVERAGE')

mtcars1_with_mean <- bind_rows( mtcars , mtcars1a_mean) %>% arrange(cyl)
mtcars1_with_mean

This topic was automatically closed 7 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.