Hello,

Try the following.

dat <- read.table(text = "
| colA | colB | colC | colD |
| NA | pumpkin | NA | Pumpkin |
| Cassava | NA | NA | Cassava |
| yam | NA | NA | yam |
| NA | Cherry | NA | Cherry |
| NA | NA | Pepper | Pepper |
| NA | NA | Mango | Mango |
| maize | NA | NA | maize |
", header = TRUE, sep = "|", stringsAsFactors = FALSE, na.strings = " NA ")

dat <- dat[, -c(1, 6)]

dat1 <- dat[, -4]

res <- apply(dat1, 1, function(x) x[!is.na(x)])
res

And please post your data examples using ?dput, it's not the first time you post to R-Help.

Hope this helps,

Rui Barradas


Em 21-11-2016 21:26, Olu Ola via R-help escreveu:
  Hello,I have the following data
| colA | colB | colC | colD |
| NA | pumpkin | NA | Pumpkin |
| Cassava | NA | NA | Cassava |
| yam | NA | NA | yam |
| NA | Cherry | NA | Cherry |
| NA | NA | Pepper | Pepper |
| NA | NA | Mango | Mango |
| maize | NA | NA | maize |


All I want to do is to combine the first three columns in order to obtain the 
fourth column.
A way forward will be greatly appreciated.

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to