[R] The "$" operator and vectors

Peter Dalgaard P.Dalgaard at biostat.ku.dk
Fri Jul 13 12:41:20 CEST 2007


Gustaf Rydevik wrote:
> Hi all,
>
> I've run into a slightly illogical (to me) behaviour with the "$"
> subsetting function.
>
> consider:
>   
>> Test
>>     
>   A B
> 1 1 Q
> 2 2 R
>
>   
>> Test$A
>>     
> [1] 1 2
>
>   
>> vector<-"A"
>> Test$vector
>>     
> NULL
>
>   
>> Test$"A"
>>     
> [1] 1 2
>
>   
>> Test[,vector]
>>     
> [1] 1 2
>
>
> Is there a reason for the $ operator not evaluating the vector before executing?
>   
Yes, the evaluation rule for "$" is like that....

Notice that it also didn't go looking for an object called A when you
said test$A.


-- 
   O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)                  FAX: (+45) 35327907



More information about the R-help mailing list