更改矩阵

时间:2016-03-09 19:39:57

标签: r

我正在尝试更改矩阵中逗号之后的值的数量:

95%     CI 
lower   upper     mean
1,0345  1,4567    1,0987
1,0965  1,2345    1,3458
3,4958  4,5969    2,3094
...

我需要在逗号到2之后减少数字,例如1,23。 我正在尝试用%02f进行冲刺,但它没有用。 请问你能帮帮我吗。 感谢您的任何建议。

1 个答案:

答案 0 :(得分:0)

substr将有效:

> matrix(c("1,0345","1,4567","1,0987","1,0965","1,2345","1,3458"),2,3)
     [,1]     [,2]     [,3]    
[1,] "1,0345" "1,0987" "1,2345"
[2,] "1,4567" "1,0965" "1,3458"

> substr(matrix(c("1,0345","1,4567","1,0987","1,0965","1,2345","1,3458"),2,3),1,4)
     [,1]   [,2]   [,3]  
[1,] "1,03" "1,09" "1,23"
[2,] "1,45" "1,09" "1,34"