Having a data.table like the following:
a <- data.table(col1 = c(1, 2, 3, NA, NA),
col2 = c(NA, NA, NA, 4, 5),
col3 = c("a", "b", "c", NA, NA),
col4 = c(NA, NA, NA, "d", "e"))
I would like to find a way to unify col1 with col2, and col3 with col4 by skipping the NAs and keeping only the values, with an output like the following:
col1 col2
<num> <char>
1: 1 a
2: 2 b
3: 3 c
4: 4 d
5: 5 e
Is there any way to achieve that? I was thinking to use the sum, but of course it doesn't work with character columns then.