开发者

How can I read a matrix with missing end elements in R?

I would like to pass to R a txt file with a matrix, where tailing zeros are o开发者_如何学JAVAmitted from rows (except the first tailing zero, if any). Those missing values considered as zeros.

for example:

8 7 0
5 4 3 2 1
4 8 9

should be read as:

8 7 0 0 0
5 4 3 2 1
4 8 9 0 0

The max row size (i.e. the number of matrix columns) is unknown prior to reading the matrix.


d <- as.matrix(read.table(filename, fill=T))
d[is.na(d)] <- 0
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜