Reputation: 151
I have a data frame with multiple columns, such as the example:
V1 V2 V3 V4
1 1234567890 1234567890 1234567890 1234567890
I want to join all columns into one. The number of columns in the dataframe can vary, is there any way to make a union without having to subsets?
In this case, I want to have this result:
TAGS_LIST
1234567890
1234567890
1234567890
1234567890
Upvotes: 0
Views: 84
Reputation: 99341
You can simply transpose the data frame. This will coerce it to class "matrix".
However, we can re-class it by wrapping the transposition with data.frame
.
> d
V1 V2 V3 V4
1 1234567890 1234567890 1234567890 1234567890
> d2 <- data.frame(t(d))
> names(d2) <- "TAGS_LIST"
> d2
TAGS_LIST
V1 1234567890
V2 1234567890
V3 1234567890
V4 1234567890
> class(d2)
[1] "data.frame"
Upvotes: 1