From murdoch.duncan at gmail.com  Wed May 26 13:50:47 2010
From: murdoch.duncan at gmail.com (Duncan Murdoch)
Date: Wed, 26 May 2010 07:50:47 -0400
Subject: [Rd] Indexing bug?
In-Reply-To: <4BFCF092.2010501@gmail.com>
References: <4BFCF092.2010501@gmail.com>
Message-ID: <4BFD0B17.5020407@gmail.com>

Duncan Murdoch wrote:
> Is this expected behaviour?
>
> x <- factor(c("c", "b", "a","c"))
> results <- c(c=4, b=5)
> results[x]
>
> giving
>
>  > results[x]
> <NA>    b    c <NA>
>   NA    5    4   NA
>
> (i.e. it appears to give results[levels(x)]
>   

Thanks to all for pointing out my misinterpretation.    It's clearly not 
a bug.

Duncan Murdoch
>
> whereas results[as.character(x)] does what I expected:
>
> as.character(x)
> results[as.character(x)]
>
>  > as.character(x)
> [1] "c" "b" "a" "c"
>  > results[as.character(x)]
>    c    b <NA>    c
>    4    5   NA    4
>
> Duncan Murdoch
>



[Rd] Indexing bug?
Duncan Murdoch