I have a really simple problem but haven't been able to find a solution. I am hoping someone can help. I have a dataframe test3
:
test3 <- structure(list(A = c(1L, 2L, NA, 4L), B = c(NA, NA, 3L, NA)), .Names = c("A",
"B"), class = "data.frame", row.names = c(NA, -4L))
A B
1 1 NA
2 2 NA
3 NA 3
4 4 NA
and I would like to combine/merge the columns A
and B
into a third column C
to give
A B C
1 1 NA 1
2 2 NA 2
3 NA 3 3
4 4 NA 4
This seems like a very common problem with a simple solution, yet I can't find a solution in my searches of stackoverflow or google. Can anyone point me in the right direction?
EDIT: My example above shows only two columns, but I will be working in a much larger dataframe with many more columns (yet I will still need to combine only two columns). If anyone could recommend a general solution to merge two columns in a big dataframe, i'd appreciate it!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…