How can I read a matrix with missing end elements in R? -
i pass r txt file matrix, tailing zeros omitted rows (except first tailing zero, if any). missing values considered zeros.
for example:
8 7 0 5 4 3 2 1 4 8 9
should read as:
8 7 0 0 0 5 4 3 2 1 4 8 9 0 0
the max row size (i.e. number of matrix columns) unknown prior reading matrix.
d <- as.matrix(read.table(filename, fill=t)) d[is.na(d)] <- 0
Comments
Post a Comment