[R] variable driven summary of one column

Chuck Cleland ccleland at optonline.net
Thu Jun 25 14:32:53 CEST 2009


On 6/25/2009 5:44 AM, Anne Skoeries wrote:
> Hello,
> 
> how can I get a variable driven summary of one column of my data.frame?
> 
> Usually I would do
>> summary(data$columnname) to get a summary of column named "columnname"
> of my data.frame named "data".
> 
> In my case the columnname is not static but can be set dynamically.
> So I save the chosen columname in something like
> variable <- "columnname"
> but how can I now get the summary of the specified column?
> 
> summary(data$get("variable")) doesn't work.
> summary(paste("data$", variable, sep="") doesn't work either!
> and if I try
> summary(data[get("variable)] it gives me back a different result since
> the data isn't a factor anymore but a list.

vname <- "Species"

summary(subset(iris, select=vname))
       Species
 setosa    :50
 versicolor:50
 virginica :50

vname <- "Sepal.Width"

summary(subset(iris, select=vname))
  Sepal.Width
 Min.   :2.000
 1st Qu.:2.800
 Median :3.000
 Mean   :3.057
 3rd Qu.:3.300
 Max.   :4.400

> Thanks for the help,
> Anne
> 
> ______________________________________________
> 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. 

-- 
Chuck Cleland, Ph.D.
NDRI, Inc. (www.ndri.org)
71 West 23rd Street, 8th floor
New York, NY 10010
tel: (212) 845-4495 (Tu, Th)
tel: (732) 512-0171 (M, W, F)
fax: (917) 438-0894




More information about the R-help mailing list