Home > OS >  How to combine tibble in R
How to combine tibble in R

Time:11-11

I am trying to combine 3 tibbles into one large tibble. The 3 tibbles have varying lengths, but the variables in each tibble are the same

I am trying to combine 3 tibbles into one large tibble. The 3 tibbles have varying lengths, but the variables in each tibble are the same

CodePudding user response:

In Base R,

I would rather use vectorization instead of creating three different tibbles per country by this:

data_filtered <- Clean_data[Clean_data$country %in% c("United States of America", "Mexico", "Canada"),]

If you just want to combine the three tibbles rbind() works well if the columns are identical.

data_filtered <- rbind(data1, data2, data3)

CodePudding user response:

dplyr's bind_rows() is useful for combining data frames wherein the columns are all identical. (bind_cols() being the equivalent for combining data frames in order to add columns to existing rows).

new_data <- bind_rows(data1, data2, data3)
  •  Tags:  
  • r
  • Related