1

I have 2 data frames in R: A & B. A contains one column ("X1") with 138 obs. and B contains one column ("term") with 520 obs. I want to combine both into one new dataframe with only one column, which thus will contain 138+520=658 observations.

My data:

A:

         X1
1       word1
2       word2
3       word3
4       word4
.
.
138     word138 

B:

        term
1       word139
2       word140
3       word141
4       word142
.
.
520     word658

They are all different words (from both sets). I want to create a new dataset ("C") which will look like:

         X
1       word1
2       word2
3       word3
4       word4
.
.
139     word139
.
.
658     word658
Ja123
  • 73
  • 6

2 Answers2

2

You could use rbind after ensuring that they both have the same names:

 C <- rbind(setNames(A, 'X'), setNames(B, 'X'))

Another way is to concatenate the two:

 C <- data.frame(X = c(A$X1, B$term))
zx8754
  • 52,746
  • 12
  • 114
  • 209
Onyambu
  • 67,392
  • 3
  • 24
  • 53
0

We could use bind_rows after renaming the colnames to X

library(dplyr)

colnames(A) <- "X"
colnames(B) <- "X"
bind_rows(A, B)
TarJae
  • 72,363
  • 6
  • 19
  • 66