Probably use the apply
function. If the data frame (df
) has only 6 columns, you can just omit the first column with df[,-1]
. Then apply the rbind
function to every row (MARGIN=1) and combine the values into a vector with the c
function.
c(apply(df[,-1], MARGIN=1, rbind))
Reproducible example
Using the mtcars data:
> df <- mtcars[1:6]
> head(df)
mpg cyl disp hp drat wt
Mazda RX4 21.0 6 160 110 3.90 2.620
Mazda RX4 Wag 21.0 6 160 110 3.90 2.875
Datsun 710 22.8 4 108 93 3.85 2.320
Hornet 4 Drive 21.4 6 258 110 3.08 3.215
Hornet Sportabout 18.7 8 360 175 3.15 3.440
Valiant 18.1 6 225 105 2.76 3.460
> x <- c(apply(df[,-1], 1, rbind))
> head(x,20)
[1] 6.000 160.000 110.000 3.900 2.620 6.000 160.000 110.000 3.900 2.875
[11] 4.000 108.000 93.000 3.850 2.320 6.000 258.000 110.000 3.080 3.215