Here is one possibility:
> gets <- function(pos) get(search()[pos])
> attach(iris)
> summary(gets(2))
Sepal.Length Sepal.Width Petal.Length Petal.Width
Min. :4.300 Min. :2.000 Min. :1.000 Min. :0.100
1st Qu.:5.100 1st Qu.:2.800 1st Qu.:1.600 1st Qu.:0.300
Median :5.800 Median :3.000 Median :4.350 Median :1.300
Mean :5.843 Mean :3.057 Mean :3.758 Mean :1.199
3rd Qu.:6.400 3rd Qu.:3.300 3rd Qu.:5.100 3rd Qu.:1.800
Max. :7.900 Max. :4.400 Max. :6.900 Max. :2.500
Species
setosa :50
versicolor:50
virginica :50
On Nov 7, 2007 2:27 PM, Jeff Marcus <Jeffrey.Marcus at nuance.com>
wrote:> When I attach data frames I often want to be able to refer to the whole
> data frame rather then one of its components. For example:
>
>
>
> attach (my.data.frame)
>
> summary(my.data.frame)
>
>
>
> That's fine but often the frame has a very long name so I'd prefer
some
> shorthand way of referring to it by its position on the search list.
> This applies especially to cases where I have a nested data frame so I
> might do
>
>
>
> attach(my.data.frame$mycomponent)
>
> summary(my.data.frame$mycomponent)
>
>
>
> I have a recollection that there was a way of doing this with S-Plus
> but I haven't been able to figure out how to do it in R (I have looked
> at attach, get, sys.frame, etc. to no avail).
>
>
>
> Is there a built-in way of doing this? Thanks.
>
>
>
> Jeff
>
>
>
>
> [[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.
>