I want to unite these data frames so that I can then work by making regressions between variables of the different data frames. How can I unite all the data frames into one?
library(dplyr)
library(readxl)
library("tidyverse")
library(caret)
data_p <- read_excel("C:/Users/x/Desktop/regresion.xlsx")
data_t_dic <- read_excel("C:/Users/x/Desktop/temperatura_mensual.xlsx",
sheet = "dic")
data_t_ene <- read_excel("C:/Users/x/Desktop/temperatura_mensual.xlsx",
sheet = "ene")
data_t_feb <- read_excel("C:/Users/x/desktop/temperatura_mensual.xlsx",
sheet = "feb")
df_p <- data.frame(data_p)
df_t_d <- data.frame(data_t_dic)
df_t_e <- data.frame(data_t_ene)
df_t_f <- data.frame(data_t_feb)
Since you're using
tidyverse/dplyr
you can take advantage of the verbunion_all()
, as long as eachdata.frame
has the same structure:In base R it is not complex either, if we use
rbind()
The ´bind_rows()´ function of ´dplyr´ does exactly that.
It accepts as argument data.frame names separated by commas, in your case it would be
An advantage (or disadvantage, depending on the particular use case) is that ´bind_rows()´ will produce a joined data.frame even if the order of the columns is not the same, since the binding is done by names and not by positions . Even when not all df's have the same columns it produces an output by padding with 'NA' in data.frames that don't have a column.
Another interesting feature is that we can pass it the names or directly a list containing data.frames
Example:
It has served me a lot working with slightly different databases.