Reputation: 1492
Refer the below code.
id <- 1:10
. How the warning can be avoided?
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
Upvotes: 2
Views: 85
Reputation: 3710
Other roads:
if ( all( is.element(x, y) ) )
if ( setequal( x, intersect(x, y) ) )
Upvotes: 0
Reputation: 66819
To check whether one vector lies entirely inside another, use all
:
if ( all(x %in% y) )
Upvotes: 6