>> apply(mt, 1, function(x) x[!is.nan(x)] ) > [[1]] > [1] 1 3 > > [[2]] > [1] 4 5 6
You need to be a little careful with apply: > mt2 <- matrix(c(1,4,2,5,3,6),2,3) > apply(mt2, 1, function(x) x[!is.nan(x)] ) [,1] [,2] [1,] 1 4 [2,] 2 5 [3,] 3 6 Depending on the input you will get a list or matrix as output. Hadley -- Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University http://had.co.nz/ ______________________________________________ R-help@r-project.org mailing list 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.