'names' attribute must be the same length as the vector

前端 未结 6 1919
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-15 19:00

Stuck on an error in R.

    Error in names(x) <- value : 
      \'names\' attribute must be the same length as the vector

What does thi

6条回答
  •  生来不讨喜
    2020-12-15 20:02

    Depending on what you're doing in the loop, the fact that the %in% operator returns a vector might be an issue; consider a simple example:

    c1 <- c("one","two","three","more","more")
    c2 <- c("seven","five","three")
    
    if(c1%in%c2) {
        print("hello")
    }
    

    then the following warning is issued:

    Warning message:
    In if (c1 %in% c2) { :
      the condition has length > 1 and only the first element will be used
    

    if something in your if statement is dependent on a specific number of elements, and they don't match, then it is possible to obtain the error you see

提交回复
热议问题