-1

I have two data frames one with 94 rows and 167 columns (df_1) and the other one with 94 rows and 1 column (df_2) and I would like to do 167 different data frames with each column of the first data frame and the same column of the second data frame, I have tried with a for loop like the next

for (i in seq_len(ncol(df_1))){
    df_[[i]] <- data.frame(df_1[sort(rownames(df_1)),i,df_2[sort(rownames(df_2)),])
}

But it does not work, can someone help me?

Maurits Evers
  • 49,617
  • 4
  • 47
  • 68
  • Please include a [minimal & reproducible code example including sample data](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) and expected output. – Maurits Evers Sep 24 '18 at 04:25

1 Answers1

0

I think to join two df if they have similar column name use the below code

library(gtools)
df3<- smartbind(df1,df2)  ####df1 with 167 column and df2 with 1 column 

this will give you a single data frame and to create various data frames use the answer used. in the below thread:

How to loop through the columns in an R data frame and create a new data frame using the column name in each iteration?

Hunaidkhan
  • 1,411
  • 2
  • 11
  • 21