将-1,0,1分配给一个数字,并将其分配给多个

时间:2018-06-13 16:17:03

标签: r sign rank

这是我的编码

no=10;mu<-10;sigma1<-1;dat <- matrix(rnorm(no, mu,sigma1), ncol = 5);dat
rnk=apply(dat,1,rank);rnk
diffe=apply(dat,1,function(x)x[]-mu);diffe

我需要继续...... 如果diffe值为正数,则为该数字指定1,将0指定为零,将负数指定为-1作为sign。之后,多个1/0 / -1,各自的数字排名为SR。 例如,

no=10;mu<-10;sigma1<-1;dat <- matrix(rnorm(no, mu,sigma1), ncol = 5);dat
          [,1]      [,2]     [,3]      [,4]     [,5]
[1,] 10.514413 10.123087 8.768467 10.926197 9.818231
[2,]  9.048713  9.814045 10.00000  9.641175 9.500561

rnk=apply(dat,1,rank);rnk
     [,1] [,2]
[1,]    4    1
[2,]    3    4
[3,]    1    5
[4,]    5    3
[5,]    2    2

diffe=apply(dat,1,function(x)x[]-mu);diffe
[1,]  0.5144132 -0.9512866
[2,]  0.1230869 -0.1859549
[3,] -1.2315329  0.0000000
[4,]  0.9261974 -0.3588249
[5,] -0.1817694 -0.4994389

sign
[1,]  1 -1
[2,]  1 -1
[3,] -1  0
[4,]  1 -1
[5,] -1 -1

SR(rnk * sign)

第一个数字= 4 * 1 + 3 * 1 + 1 * -1 + 5 * 1 + 2 * -1 = 9

第二个数字= 1 * -1 + 4 * -1 + 5 * 0 + 3 * -1 + 2 * -1 = -10

谢谢.. =]]

0 个答案:

没有答案