繁体   English   中英

警告消息:要替换的项目数不是替换长度的倍数

[英]Warning messages: number of items to replace is not a multiple of replacement length

我需要帮助解决这个问题。 它发生在我为我的估算器运行循环时。谁能告诉我这个问题会影响我的结果吗?

#转换数据的样本选择##

`s<-sample(1:50,2,replace = FALSE,prob = NULL) s;data$Wy[s] s<-sample(1:50,2,replace = FALSE,prob = NULL) s;data $Wx[s]``

##loop for ratio estimator##
>`for(i in 1:10) 
{
  s[i]<-sample(1:50,2,replace=FALSE, prob = NULL)
  wr[i]<-  mean(data$Wy[s])/mean(data$Wx[s])  
  muwr[i]<-wr[i]*muwx                     ##ratio type mean estimator##
}`

##输出警告信息##

`1: In s[i] <- sample(1:50, 2, replace = FALSE, prob = NULL) :
  number of items to replace is not a multiple of replacement length
2: In s[i] <- sample(1:50, 2, replace = FALSE, prob = NULL) :
  number of items to replace is not a multiple of replacement length
3: In s[i] <- sample(1:50, 2, replace = FALSE, prob = NULL) :
  number of items to replace is not a multiple of replacement length
4: In s[i] <- sample(1:50, 2, replace = FALSE, prob = NULL) :
  number of items to replace is not a multiple of replacement length
5: In s[i] <- sample(1:50, 2, replace = FALSE, prob = NULL) :
  number of items to replace is not a multiple of replacement length
6: In s[i] <- sample(1:50, 2, replace = FALSE, prob = NULL) :
  number of items to replace is not a multiple of replacement length
7: In s[i] <- sample(1:50, 2, replace = FALSE, prob = NULL) :
  number of items to replace is not a multiple of replacement length
8: In s[i] <- sample(1:50, 2, replace = FALSE, prob = NULL) :
  number of items to replace is not a multiple of replacement length
9: In s[i] <- sample(1:50, 2, replace = FALSE, prob = NULL) :
  number of items to replace is not a multiple of replacement length
10: In s[i] <- sample(1:50, 2, replace = FALSE, prob = NULL) :
  number of items to replace is not a multiple of replacement length
> muwr
 [1] 1155.006 1155.021 1154.958 1154.875 1154.774 1154.875 1155.021 1155.021 1155.021
[10] 1155.006
> mean(muwr);var(muwr)
[1] 1154.958
[1] 0.007579488`

s[i] <- sample(1:50, 2, replace=FALSE, prob = NULL)

sample(1:50, 2, ...)将返回一个长度为 2 的向量。我猜s是一个数字向量,您正试图放入 position i不是一个元素,而是两个元素,因此您在每次迭代中看到的警告。 也许你想要sample(1:50, 1, ...)

我不知道最终结果将如何受到影响,但我建议您无论如何都要解决不一致的问题。

s[i] <- sample(1:50, 2, replace=FALSE, prob = NULL) 在上面的语句中我做错的是我使用 s[i] 而不是 s,这个问题导致了警告信息并且还会影响样本选择命令。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM