I have the following matrix:
V1 V2 V3 V4 V4
[1,] "a" "j" "d" "e" NA
[2,] "a" "b" "d" "e" NA
[3,] "a" "j" "g" "f" NA
[4,] "a" "g" "f" NA NA
I want to get:
V1 V2
[1,] "ajde"
[2,] "abde"
[3,] "ajgf"
[4,] "agf"
I know how to reduce a matrix to one column by using matrix(do.call(paste0, as.data.frame(M)))
and how to remove the NA by row using m[!is.na(m[i,])]
. I just do not know how to but the two together as any time I try to use m[!is.na(m)] on the whole matrix, I end up with one large row