[R] indexing question

jim holtman jholtman at gmail.com
Tue Jan 13 16:23:34 CET 2009


How about this:

> data(ToothGrowth)
> ls()
[1] "ToothGrowth"
> data <- function(x){invisible(NULL)}
> data(ToothGrowth)
> ls()
[1] "data"
>


On Tue, Jan 13, 2009 at 9:53 AM, Ista Zahn <istazahn at gmail.com> wrote:
> From: baptiste auguie <ba208 at exeter.ac.uk>
> To: Dimitris Rizopoulos <d.rizopoulos at erasmusmc.nl>
> Date: Tue, 13 Jan 2009 09:38:09 +0000
> Subject: Re: [R] indexing question
>
>> you can also look at subset,
>>
>>
>>        my.data.frame <- data.frame(a=rnorm(10),
>>> b=factor(sample(letters[1:4], 10, replace=T)))
>>>        str(my.data.frame)
>>>        my.data.frame[my.data.frame$b == "a", ]
>>>        subset(my.data.frame, b == "a")
>>>
>>
>> by the way, it is probably safer not to use "data" as a variable name as it
>> is also a function.
>>
>
> I've often wondered about this. The thing is, I've never run into a problem
> with this. For example:
>
>> ls()
> character(0)
>> data(ToothGrowth)
>> ls()
> [1] "ToothGrowth"
>> rm(ToothGrowth)
>> ls()
> character(0)
>> data <- data.frame(1:10, 101:110)
>> data(ToothGrowth) #works just the same
>> ls()
> [1] "data"        "ToothGrowth"
>>
>
> In this example the data command works just the same the second time, even
> though I have a data.frame named data. Can someone give an example where
> this causes a problem?
>
> Thanks,
> Ista
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?




More information about the R-help mailing list