Skip to content
Prev 35823 / 63424 Next

Confusing error message for [[.factor (PR#14209)

On 09/02/2010 4:50 AM, g.russell at eos-solutions.com wrote:
I don't see that.  I get this:

 >  c("a","b")[[c(TRUE,FALSE)]]
Error in c("a", "b")[[c(TRUE, FALSE)]] :
  recursive indexing failed at level 1

which differs because c("a", "b") is not a factor.
No, because it sometimes does work with logical index vectors:

 > x <- 1:2
 > x[[TRUE]]
[1] 1

(Here the TRUE is treated as 1.  I think it only works when the logical 
vector contains TRUE values, FALSE will fail, just as x[[0]] fails.)

The problem is that you were asking for the FALSE entry of the TRUE 
entry of the object, and since you had a simple vector, recursive 
indexing fails, and that's what the message says.  I imagine you had 
meant to type c("a", "b")[c(TRUE, FALSE)], but how can R know you meant 
that?

Duncan Murdoch