r语言sort函数中index是什么意思

Python012

r语言sort函数中index是什么意思,第1张

是一逻辑值,决定索引向量是否也要返回。注意只对某些情况有效。查到的参数说明如下:

index.returnlogical indicating if the ordering index vector should be returned as wellthis is only available for a few cases, the default na.last = NA and full sorting of non-factors.

如果空的地方用NA 表示的话,那么就可以用如下编码实现

假设 第一组数据是 a1  第二组数据是a2, 他们的行数是一致的!

index<- is.na(a1)

a1[index] <- a2[index]

# here is a example

a1<-c(1,NA,3,NA,5,6,NA,8,9,10)

a1

a2<- 1:10

a2

length(a1)

length(a2)

index<-is.na(a1)

a1[index]<-a2[index]

a1

结果截图:

不知道是不是你想要的结果~

如果你能提供数据结构的话,我或许可以更加明确的提供方法!