需要在我的数据中对NA排序,而不影响R中矩阵中的数字的秩

需要在我的数据中对NA排序,而不影响R中矩阵中的数字的秩,r,matrix,rank,na,R,Matrix,Rank,Na,下面是我的代码 这个问题很不清楚。我之所以能听懂,是因为你昨天问了一个类似的问题,我记得。希望这能回答你的问题 首先,您创建的矩阵不正确。(我认为)你实际上想要的4和5是: four<-matrix(c(6678,5677,6767,5555,1111,1112),3,2) five<-matrix(c(5555,1112,1111,2222,1212,9999),3,2) four为什么要以生成警告的方式创建矩阵?这里有一个问题吗(带“?”)?嗨,弗兰克,这些是生成的警告,在底部

下面是我的代码


这个问题很不清楚。我之所以能听懂,是因为你昨天问了一个类似的问题,我记得。希望这能回答你的问题

首先,您创建的矩阵不正确。(我认为)你实际上想要的
4
5
是:

four<-matrix(c(6678,5677,6767,5555,1111,1112),3,2)
five<-matrix(c(5555,1112,1111,2222,1212,9999),3,2)

four为什么要以生成警告的方式创建矩阵?这里有一个问题吗(带“?”)?嗨,弗兰克,这些是生成的警告,在底部是我试图生成的警告。@agstudy将在将来执行。谢谢你的意见。@agstudy刚刚重新安排,谢谢教授如果我让你不高兴的话,我是一个新的研究生,在编码方面很差劲。不用担心,我没有不高兴。这显然是你一直在解决的一个实际问题,而不仅仅是你剪切粘贴的作业,所以问这样的问题是可以的。我希望这是有帮助的。这给了我需要的最终输出,最终通过我的数据。非常感谢!!!!!!!
## order all data by second column and spit out NAs if number in second column of 
## previous matrix  doesnt match first column of new matrix
onea<-one[order(one[,2]),];
twoa<-two[order(two[,1])[rank(onea[,2])],];
threea<-three[order(three[,1])[rank(twoa[,2])],]
foura<-four[order(four[,1])[rank(threea[,2])],]
fivea<-five[order(five[,1])[rank(foura[,2])],]
finaltable<-cbind(onea,twoa,threea,foura,fivea)
Warning message:
In matrix(c(6678, 5677, 6767, 5555, 1111, 1112), 4, 2) :
  data length [6] is not a sub-multiple or multiple of the number of rows [4]
>     five<-matrix(c(5555,1112,1111,2222,1212,9999),4,2);
Warning message:
In matrix(c(5555, 1112, 1111, 2222, 1212, 9999), 4, 2) :
  data length [6] is not a sub-multiple or multiple of the number of rows [4]
finaltable
     [,1]  [,2]  [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
[1,] 2004 12345 12345 7777 7777 6789 NA     NA   NA    NA
[2,] 2001 23456 23456 3456 3456 5677 5677 1111 1111  8888
[3,] 2002 23567 23567 2345 2345 6678 6678 5555 5555  2222
[4,] 2003 54321 54321 1234 1234 6767 6767 1112 1112  9999
four<-matrix(c(6678,5677,6767,5555,1111,1112),3,2)
five<-matrix(c(5555,1112,1111,2222,1212,9999),3,2)
 matchOrder<-function(x,y){
   y[match(x[,2],y[,1]),]
 }
 onea <- one[order(one[,2]),]
 twoa <- matchOrder(onea,two)
 threea <- matchOrder(twoa,three)
 foura <- matchOrder(threea,four)
 fivea <- matchOrder(foura,five)
 finaltable <- cbind(onea,twoa,threea,foura,fivea)
 finaltable
     [,1]  [,2]  [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
[1,] 2004 12345 12345 7777 7777 6789   NA   NA   NA    NA
[2,] 2001 23456 23456 3456 3456 5677 5677 1111 1111  9999
[3,] 2002 23567 23567 2345 2345 6678 6678 5555 5555  2222
[4,] 2003 54321 54321 1234 1234 6767 6767 1112 1112  1212
l <- list(two,three,four,five)
do.call(cbind,Reduce(matchOrder,l,onea,accumulate=T))
     [,1]  [,2]  [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
[1,] 2004 12345 12345 7777 7777 6789   NA   NA   NA    NA
[2,] 2001 23456 23456 3456 3456 5677 5677 1111 1111  9999
[3,] 2002 23567 23567 2345 2345 6678 6678 5555 5555  2222
[4,] 2003 54321 54321 1234 1234 6767 6767 1112 1112  1212