Hi all, I've run into a slightly illogical (to me) behaviour with the "$" subsetting function. consider:> TestA B 1 1 Q 2 2 R> Test$A[1] 1 2> vector<-"A" > Test$vectorNULL> Test$"A"[1] 1 2> Test[,vector][1] 1 2 Is there a reason for the $ operator not evaluating the vector before executing? best, Gustaf -- Gustaf Rydevik, M.Sci. tel: +46(0)703 051 451 /+46(0)8 760 52 93 address: C/O Rydevik, Syrenv. 12, 17851 Eker?, SE skype:gustaf_rydevik
Gustaf Rydevik <gustaf.rydevik <at> gmail.com> writes:> Is there a reason for the $ operator not evaluating > the vector before executing?Yes. Consider:> x <- list(a = 1, b = 'n') > a <- 'b' > x[[a]] == 'n'[1] TRUE> x[['a']] == 1[1] TRUE> x$a == ???If the result is 'n', then all bare $ references would require quotes to avoid name collisions. THK> > best, > > Gustaf >
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
Seemingly Similar Threads
- New errors with difftime()-objects in 2.11.1 (was Re: Request: difftime method for cut())
- New errors with difftime()-objects in 2.11.1 (was Re: Request: difftime method for cut())
- download.file not working
- Change the position of panel strips in a lattice plot.
- two-sample test of multinomial proportion