开发者

In r, how can I create a list from a matrix with NAs stripped?

I ha开发者_如何学Pythonve a character matrix with differing numbers of NA in different rows. I would like to create a structure that has the same number of rows, with all the NAs removed.


Using a simple apply :

x <- matrix(1:10,ncol=2)
x[c(4,7,8)] <- NA

apply(x,1,na.exclude)

edit : if all rows have exactly the same amount of NA's, then this will return a matrix. For conversion of this matrix to a list, see : How to convert a matrix to a list of column-vectors in R? .

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜