0

I'm very new to R, so it might be a very easily solved question. I couldn't find a solution though, maybe I had wrong keywords.

How do I stack the columns of a dataframe onto each other, while deleting the other ones? I tried converting it into a list but that didn't work out.

This is how the table looks like:

    A     B     C
    tulip thyme grass
    grass
    fern  thyme tulip

This would be what I need as a final result

    A
    tulip
    thyme
    grass
    fern

unique(my dataframe) doesn't work either.

Thank you for your help!

viomouse
  • 1
  • 1
  • 3

1 Answers1

1

Maybe you can try

> data.frame(A = unique(na.omit(c(t(df)))))
      A
1 tulip
2 thyme
3 grass
4  fern

data

> dput(df)
structure(list(A = c("tulip", "grass", "fern"), B = c("thyme", 
NA, "thyme"), C = c("grass", NA, "tulip")), class = "data.frame", row.names = c(NA,
-3L))
ThomasIsCoding
  • 96,636
  • 9
  • 24
  • 81