Use max on each element of a matrix

后端 未结 3 1234
情话喂你
情话喂你 2021-01-18 05:05
> x <- array(-10:10, dim=c(4,5))
> x
     [,1] [,2] [,3] [,4] [,5]
[1,]  -10   -6   -2    2    6
[2,]   -9   -5   -1    3    7
[3,]   -8   -4    0    4    8         


        
3条回答
  •  没有蜡笔的小新
    2021-01-18 05:54

    It appears that the order of the arguments to pmax() affects the class of what is returned when the input is a matrix:

    pmax(0,x)
    [1] 0 0 0 0 0 0 0 0 0 0 0 1 2 3 4 5 6 7 8 9
    
    pmax(x,0)
         [,1] [,2] [,3] [,4] [,5]
    [1,]    0    0    0    2    6
    [2,]    0    0    0    3    7
    [3,]    0    0    0    4    8
    [4,]    0    0    1    5    9
    

提交回复
热议问题