2
請參閱下面的代碼。
id <- 1:10
。如何避免警告?檢查R中的矢量值
allFiles <- list.files(directory)
fileRange <- c(1:length(allFiles))
if(!(as.numeric(id) %in% fileRange))
{
print("Invalid file range")
stop()
}
Warning: the condition has length > 1 and only the first element will be used
也許你想'如果(所有(我d%in%seq_along(fileRange)))'? – Frank
@Frank是的。感謝它的工作。 –