找到每列的最大值和最小值,然后找到每一行的最大值和最小值

时间:2023-02-04 16:05:49

I've got this matrix:

我有这个矩阵:

a <- matrix(rnorm(1000 * 18, mean = 100, sd = sqrt(10)), 1000, 18)

I would like to find the maximum and minimum value of every column and the maximum and minimum value of every row.

我想找到每列的最大值和最小值以及每行的最大值和最小值。

3 个解决方案

#1


35  

Figured it out.

弄清楚了。

Minimum and maximum of every column:

每列的最小值和最大值:

apply(a,2,min)
apply(a,2,max)

Minimum and maximum of every row:

每行的最小值和最大值:

apply(a,1,min)
apply(a,1,max)

Found the information here http://www.personality-project.org/r/r.commands.html

在http://www.personality-project.org/r/r.commands.html找到了相关信息

#2


2  

See the matrixStats package. You can use colMins(), rowMaxs() and functions like this both for columns and rows.

请参阅matrixStats包。您可以对列和行使用colMins(),rowMaxs()和类似函数。

See this answer: How to find the highest value of a column in a data frame in R?

请参阅以下答案:如何在R中的数据框中找到列的最高值?

#3


0  

You can try

你可以试试

apply(a, 1, range)

#1


35  

Figured it out.

弄清楚了。

Minimum and maximum of every column:

每列的最小值和最大值:

apply(a,2,min)
apply(a,2,max)

Minimum and maximum of every row:

每行的最小值和最大值:

apply(a,1,min)
apply(a,1,max)

Found the information here http://www.personality-project.org/r/r.commands.html

在http://www.personality-project.org/r/r.commands.html找到了相关信息

#2


2  

See the matrixStats package. You can use colMins(), rowMaxs() and functions like this both for columns and rows.

请参阅matrixStats包。您可以对列和行使用colMins(),rowMaxs()和类似函数。

See this answer: How to find the highest value of a column in a data frame in R?

请参阅以下答案:如何在R中的数据框中找到列的最高值?

#3


0  

You can try

你可以试试

apply(a, 1, range)