argument is of length zero

Published by onesixx on

if (NULL) {}
if (logical(0)) {}

Error in if (condition) { : argument is of length zero
Error in while (condition) { : argument is of length zero

이 에러는 조건의 결과가 T/F값이 아닌 NULL 또는 logical(0)인 경우 발생한다.
특히, NULL과 무언가를 비교하려고 할때 많이 발생한다.

sixx <- 6;    if (sixx==0) print("truth") else print("lie")
#[1] "lie"

sixx <- NA;   if (sixx==0) print("truth") else print("lie")
#missing value where TRUE/FALSE needed

sixx <- NULL; if (sixx==0) print("truth") else print("lie")
#argument is of length zero

if(is.na(sixx) & length(sixx)>0){
\tif (sixx==0) print("truth") else print("lie")
}

또는 List에서 잘못된 컬럼을 부르는 경우.

LL <- list(a=TRUE, b=FALSE, c=NA)
if(LL$d) {}   
## Error in if (l$d) { : argument is of length zero
"sixx" == 6        # FALSE
"sixx" == FALSE    
"sixx" == TRUE     
"sixx" == NA       # NA
"sixx" == NULL     # logical(0)
length("sixx")         # 1
length(6)
length(FALSE)
length(NA)
length(NULL)           # 0 

Categories: Uncategorized

onesixx

Blog Owner

Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x