I have a dfs group with different headers that I need to line up: I was hoping to change the column names so that each one has the same name.
df1
name, score
smith, 3
smith, 7
smith, 5
df2
type, price
food, 3
food, 5
food, 2.6
I want to combine this so that each of them has the same name and is united by lines. I have 32 of these data frames with different headers, so I plan to use a loop
I made a list of dfs
groups <- c(df1, df2, df3, etc)
then tried to merge into empty df:
new_df <- data.frame(words=character(),numbers=numeric())
for (i in 1:length(groups))
{
x <- data.frame(words=character(),numbers=numeric())
x[,1] <- groups[i]
x[,2] <- groups[i+1]
new_df <- rbind(new_df, x)
}
Unfortunately, it just returns an empty df with a bunch of warnings. Can someone tell me how to fix this? I expected new_df to be;
words, numbers
smith, 3
smith, 7
smith, 5
food, 3
food, 5
food, 2.6
I am sure it is easy for people with a little more experience than me. thank