2

I have this format of dataframe:

df <- structure(list(col1 = structure(1:2, .Label = c("text1", "text3"
), class = "factor"), col2 = structure(c(2L, 1L), .Label = c("text1", 
"text2"), class = "factor"), col3 = structure(c(1L, 1L), .Label = "text1", class = "factor"), 
    col4 = structure(1:2, .Label = c("text2", "text4"), class = "factor")), .Names = c("col1", 
"col2", "col3", "col4"), class = "data.frame", row.names = c(NA, 
-2L))

And I would like to merge/combine all columns into one without keeping the column names.

Example output:

text1
text2
text1
text2
text3
text1
text1
text4

I found this example but it merges the rows.

M--
  • 25,431
  • 8
  • 61
  • 93
Sasak
  • 189
  • 5
  • 15

1 Answers1

2

We transpose the dataset, concatenate it to a vector and create a data.frame based on that

data.frame(newcol = c(t(df)), stringsAsFactors=FALSE)
akrun
  • 874,273
  • 37
  • 540
  • 662