[R] How x[, 'colname1'] is implemented?

Peng Yu pengyu.ut at gmail.com
Thu Dec 31 23:47:21 CET 2009


On Fri, Jan 1, 2010 at 4:24 PM, milton ruser <milton.ruser at gmail.com> wrote:
> Hi Peng,
>
> If I undertood your point, try this:
>
> x<-runif(10)
> y<-runif(10)
> z<-runif(10)
> w<-runif(10)
>
> myDF<-data.frame(cbind(x,y,z,w))
> myDF
>
> myDF[,c("w","z")]

Thank you!

But this is not what I'm asking. I want to know how R internal resolve
which columns to use if I specify the column names rather than the
indexes. If R does it by search, the access time should be O(log(n))
where n is the number of columns. If R does it by hash, the access
time should be O(1).

> On Thu, Dec 31, 2009 at 5:15 PM, Peng Yu <pengyu.ut at gmail.com> wrote:
>>
>> I don't see where describes the implementation of '[]'.
>>
>> For example, if x is a matrix or a data.frame, how the lookup of
>> 'colname1' is x[, 'colname1'] executed. Does R perform a lookup in the
>> a hash of the colnames? Is the reference O(1) or O(n), where n is the
>> second dim of x?
>>
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>
>




More information about the R-help mailing list