I have two dataframes that I want to be able to rbind together. They have the similar information in them, but not in the same order and not with the same column names (and this is a mix of strings, integers, and real numbers, so matrices will not work).
What I then need to do is convert one of the dataframes (we'll call it new_df) into the same structure as the other dataframe (we'll call it old_df).
I want to create an empty dataframe with the column structure of old_df AND the same number of rows as new_df.
I know I can create the first part of that with empty_df <- old_df[0,], but how can I specify the number of rows?
I know the number of rows I want to end up with, so I'd like to specify that. I cannot find this anywhere.
What I want is something like this (if this worked):
empty_df <- old_df[rep(0,nrow(new_df)),]
I tried:
empty_df <- old_df[rep(0,nrow(new_df)),]
- This just does the same as
old_df[0,]with 0 rows
empty_df <- old_df[0,]
empty_df$ID <- new_df$ids
- Obviously that doesn't work as I am trying to add a different number of rows
as.data.frame(matrix(,nrow(df),ncol(df)))