0

Im trying to combine two data frames in R, both with 1 column, and have them added with the columns beside each other.

Let's say I have one one data frame called names.df and another called id.df, how do I combine them (name.df and name.df) so the the names are column1 and the ids are column2?

names <- c('John','Peter','Sally')
names.df <- data.frame(names)


id <- c('12632','82174','27036')
id.df <- data.frame(id)
NelsonGon
  • 13,015
  • 7
  • 27
  • 57
cnikel
  • 1

1 Answers1

0

Use cbind:

cbind(names.df, id.df)

  names    id
1  John 12632
2 Peter 82174
3 Sally 27036

This would generate a data frame output from the two inputs.

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360