I have a list of matrices. I want to round off each element of the matrix in the list. Somehow I am not able to get how to do it. I tried the following way but it doesn't work: e.g.
a<-list(matrix(c(1:12/6),nrow=3),matrix(c(1:12/7),nrow=3),matrix(c(5:16/6),nrow=3))
a<-lapply(a,function(x) round(x,digits=5))
which gives the following output:
[[1]]
[,1] [,2] [,3]
[1,] 0.16667000000000001259 0.66666999999999998483 1.1666700000000000959
[2,] 0.33333000000000001517 0.83333000000000001517 1.3333299999999999041
[3,] 0.50000000000000000000 1.00000000000000000000 1.5000000000000000000
[,4]
[1,] 1.6666700000000000959
[2,] 1.8333299999999999041
[3,] 2.0000000000000000000
[[2]]
[,1] [,2] [,3]
[1,] 0.1428599999999999870 0.5714299999999999935 1.0000000000000000000
[2,] 0.2857100000000000195 0.7142899999999999805 1.1428599999999999870
[3,] 0.4285700000000000065 0.8571400000000000130 1.2857099999999999085
[,4]
[1,] 1.4285699999999998955
[2,] 1.5714300000000001045
[3,] 1.7142900000000000915
[[3]]
[,1] [,2] [,3]
[1,] 0.83333000000000001517 1.3333299999999999041 1.8333299999999999041
[2,] 1.00000000000000000000 1.5000000000000000000 2.0000000000000000000
[3,] 1.16667000000000009585 1.6666700000000000959 2.1666699999999998738
[,4]
[1,] 2.3333300000000001262
[2,] 2.5000000000000000000
[3,] 2.6666699999999998738
With format
function it works but it gives each element as character. When I try to convert the character elements into numeric it again returns the numbers up to many decimal places. How can I get each element of the matrices in the list as rounded numeric numbers ?