如何舍入矩阵中的所有值? [英] How to round all values in a matrix?
本文介绍了如何舍入矩阵中的所有值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用以下方法将所有相关性存储在矩阵中:
I use the following method to store all my correlations in a matrix:
corrs <- cor(dataset, use="pairwise.complete.obs")
但现在我想将逗号后的值四舍五入为两位数.我怎样才能做到这一点?我刚刚找到了一个圆形函数,但不知道如何将其应用于所有值.
But now I'd like to round the values to two digits after the comma. How can I do that? I just found a round function but don't know how to apply it to all values.
推荐答案
就像在您的其他问题中一样,使用您找到的函数 (round
) :)
Just as in your other question, use the function (round
) you found :)
corrs <- round(cor(dataset, use="pairwise.complete.obs"), 2)
例如:
> round(cor(cars),2)
speed dist
speed 1.00 0.81
dist 0.81 1.00
这篇关于如何舍入矩阵中的所有值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文