Re: [R] Newbie question on subsets

From: <Bill.Venables_at_csiro.au>
Date: Mon, 21 Jan 2008 08:54:05 +1000


This is very standard problem for neophytes. Subsetting a factor does not automatically subset the levels, so the all appear in the boxplot.

I think the simplest way round this is to replace ~ country in the formula by ~ factor(country). The call to factor() will re-set the levels to only those which appear. So try

boxplot(log(marketvalue) ~ factor(country), ## changed line

   data = subset(Forbes2000,

                 country %in%
	c("United Kingdom","Germany","India","Turkey")),
   ylab = "log(marketvalue)", varwidth = TRUE)

Bill Venables.

-----Original Message-----
From: r-help-bounces_at_r-project.org [mailto:r-help-bounces_at_r-project.org] On Behalf Of Joe Trubisz
Sent: Sunday, 20 January 2008 1:12 PM
To: R-help_at_r-project.org
Subject: [R] Newbie question on subsets

Hi...

I'm working through the book, A Handbook of Statistical Analyses using R by Everitt, and I'm trying to do the following (p. 19 of his book):

boxplot(log(marketvalue) ~ country,

   data = subset(Forbes2000,

                 country %in% 
	c("United Kingdom","Germany","India","Turkey")),
   ylab = "log(marketvalue)", varwidth = TRUE)

This *almost* works, but I'm getting ALL the countries on the x-axis, not just the 4-specified.
I tried tinkering with variations in the subset command to no avail.

Can someone tell me what's wrong/missing with the above command?

Thanks,
Joe



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.

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. Received on Sun 20 Jan 2008 - 22:58:51 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 21 Jan 2008 - 01:30:07 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive