如何检查R中另一个多数向量中是否存在多个数?

时间:2019-06-07 18:52:03

标签: r

我需要检查R中另一个数字向量中是否存在数字向量中的唯一数字。我的代码向我显示了一条警告消息。

crp_code <-
 c(41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 
41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 
41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 
41, 41, 51, 51, 51)

uni_codes <- c(11, 21, 41, 51, 81)

if (dput(unique(as.numeric(crp_code))) %in% uni_codes) {
         data <- data[(Crp %in% dput(unique(as.numeric(crp_code))))]
        } else {
          do task 2
        }

crp_code <-
 c(41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 
41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 
41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 
41, 41, 51, 51, 51)

Warning message:
In if (dput(unique(as.numeric(crp_code))) %in% dput(Gopi_crp_codes)) { :
  the condition has length > 1 and only the first element will be used

不知道为什么我收到警告消息。有什么建议可以改善我的代码吗?谢谢。

0 个答案:

没有答案