I want to combine a few dataframe vectors into a single one. Usually I would use a series of loops or something to acheive this, but I'm wondering if there is a more native way to do this in R?
Here is a sample of data that I currently have:
| A | B | C | other_data |
|------------------------|
| X | | | "foo" |
|------------------------|
| | | X | "bar" |
|------------------------|
| | X | | "baz" |
|------------------------|
| X | | | ":)" |
--------------------------
a <- c("X", NA, NA, "X")
b <- c(NA, NA, "X", NA)
c <- c(NA, "X", NA, NA)
other_data <- c("foo", "bar", "baz", ":)")
df <- data.frame(a, b, c, other_data)
And I would like to combine the A, B and C vectors into the one vector, like shown below:
| Alphabet | other_data |
|-----------------------|
| "A" | "foo" |
|-----------------------|
| "C" | "bar" |
|-----------------------|
| "B" | "baz" |
|-----------------------|
| "A" | ":)" |
-------------------------
Alphabet <- c("A","C","B","A")
other_data <- c("foo", "bar", "baz", ":)")
df <- data.frame(Alphabet, other_data)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…