0

Let's say I have

one <- mtcars[1:4, ]
two <- mtcars[1:7, ]

All I need to get is this; in a one big beautiful df without adding another col that resulted by rbind(), rbind.fill(), union() etc.

>    mpg cyl  disp  hp drat    wt  qsec vs am gear carb
#> 1 21.0   6 160.0 110 3.90 2.620 16.46  0  1    4    4
#> 1 21.0   6 160.0 110 3.90 2.620 16.46  0  1    4    4
#> 2 21.0   6 160.0 110 3.90 2.875 17.02  0  1    4    4
#> 2 21.0   6 160.0 110 3.90 2.875 17.02  0  1    4    4
#> 3 22.8   4 108.0  93 3.85 2.320 18.61  1  1    4    1
#> 3 22.8   4 108.0  93 3.85 2.320 18.61  1  1    4    1
#> 4 21.4   6 258.0 110 3.08 3.215 19.44  1  0    3    1
#> 4 21.4   6 258.0 110 3.08 3.215 19.44  1  0    3    1
#> 5 17.8   6 167.6 123 3.92 3.440 18.90  1  0    4    4
#> 6 16.4   8 275.8 180 3.07 4.070 17.40  0  0    3    3
#> 7 17.3   8 275.8 180 3.07 3.730 17.60  0  0    3    3

I know its probably a simple commend but it's giving me a hard time to figure out, Thanks.

user3698773
  • 929
  • 2
  • 8
  • 15
  • 4
    It's not clear what you want. "rbind(one,two)" gives the output you want. – JeanVuda Mar 26 '18 at 18:13
  • rbind() works only with the equal length of two cols, isn't it? – user3698773 Mar 26 '18 at 18:15
  • No, it works with any number of rows, but the two elements need to have same number of columns. – JeanVuda Mar 26 '18 at 18:16
  • Ok, Thanks I get this error: Error in match.names(clabs, names(xi)) : names do not match previous names – user3698773 Mar 26 '18 at 18:18
  • If you are getting that error, then you are not testing against the test-data you provided above. The names in the two sets of columns need to match. – r2evans Mar 26 '18 at 18:20
  • If the names don't match you'll need something that fills columns such as `data.table`s `rbindlist` or the `rbind.fill` that you mentioned. – Mike H. Mar 26 '18 at 18:29

1 Answers1

1
one <- mtcars[1:4, ]
two <- mtcars[1:7, ]

rbind(one,two)
JeanVuda
  • 1,738
  • 14
  • 29