Concatenate two columns of a data frame in R
We can transpose ( t
) the dataset and then concatenate ( c
) the output matrix
to getvector
c(t(df1))
#[1] "a1" "b1" "a2" "b2" "a3" "b3"
Or use as.vector
.
as.vector(t(df1))
#[1] "a1" "b1" "a2" "b2" "a3" "b3"
Usually used to convert 'data.frame' to 'vector' unlist
, but it will be written off column by column. This is the reason for migrating the dataset and using c
or as.vector
.
Or list
you can use to get the output as.list
.
as.list(t(df1))
source to share