bug with subset and plot?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

bug with subset and plot?

Knut Helge Jensen
Hi!

I have the following problem that I beleive is a bug:

I have a dataframe with one categorical and one numerical vector. The
categorical vector has three levels (uc, up and vc). A plot of the
vectors with the categorical vector on the x-axis gives a boxplot with
three boxes - exactly as expected.

If I then use the subset function to make a dataset that only includes
two of the levels of the categorical vector and do the plot again, all
three levels are still shown on the x-axis even though one of them
doesn't exist in the dataset. The plot shows correct number of boxes (2).

The whole syntax for what I describe is as follows:
exploration.df <- read.table('clipboard', header=T)
attach(exploration.df)
plot(treatment,total.escapes)

exp.df <- subset(exploration.df, treatment!='up')
attach(exp.df)
plot(treatment, total.escapes)

I use R version 2.9.1 (2009-06-26) for Debian.

Knut Helge Jensen


______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: bug with subset and plot?

Erik Iverson-2
http://stackoverflow.com/questions/1195826/dropping-factor-levels-in-a-subsetted-data-frame-in-r

-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On Behalf Of Knut Helge Jensen
Sent: Friday, August 07, 2009 5:02 AM
To: [hidden email]
Subject: [R] bug with subset and plot?

Hi!

I have the following problem that I beleive is a bug:

I have a dataframe with one categorical and one numerical vector. The
categorical vector has three levels (uc, up and vc). A plot of the
vectors with the categorical vector on the x-axis gives a boxplot with
three boxes - exactly as expected.

If I then use the subset function to make a dataset that only includes
two of the levels of the categorical vector and do the plot again, all
three levels are still shown on the x-axis even though one of them
doesn't exist in the dataset. The plot shows correct number of boxes (2).

The whole syntax for what I describe is as follows:
exploration.df <- read.table('clipboard', header=T)
attach(exploration.df)
plot(treatment,total.escapes)

exp.df <- subset(exploration.df, treatment!='up')
attach(exp.df)
plot(treatment, total.escapes)

I use R version 2.9.1 (2009-06-26) for Debian.

Knut Helge Jensen

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: bug with subset and plot?

Ista Zahn
In reply to this post by Knut Helge Jensen
See http://wiki.r-project.org/rwiki/doku.php?id=tips:data-manip:drop_unused_levels

-Ista

> Hi!
>
> I have the following problem that I beleive is a bug:
>
> I have a dataframe with one categorical and one numerical vector. The categorical vector has three levels (uc, up and vc). A plot of the vectors with the categorical vector on the x-axis gives a boxplot with three boxes - exactly as expected.
>
> If I then use the subset function to make a dataset that only includes two of the levels of the categorical vector and do the plot again, all three levels are still shown on the x-axis even though one of them doesn't exist in the dataset. The plot shows correct number of boxes (2).
>
> The whole syntax for what I describe is as follows:
>
> exploration.df <- read.table('clipboard', header=T)
>
> attach(exploration.df)
>
> plot(treatment,total.escapes)
>
> exp.df <- subset(exploration.df, treatment!='up')
>
> attach(exp.df)
>
> plot(treatment, total.escapes)
>
> I use R version 2.9.1 (2009-06-26) for Debian.
>
> Knut Helge Jensen

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: bug with subset and plot?

milton ruser
In reply to this post by Knut Helge Jensen
hi knut

may be:

treatment<-factor(treatment)
plot(...)

cheers
milton
On Fri, Aug 7, 2009 at 6:02 AM, Knut Helge Jensen <[hidden email]>wrote:

> Hi!
>
> I have the following problem that I beleive is a bug:
>
> I have a dataframe with one categorical and one numerical vector. The
> categorical vector has three levels (uc, up and vc). A plot of the vectors
> with the categorical vector on the x-axis gives a boxplot with three boxes -
> exactly as expected.
>
> If I then use the subset function to make a dataset that only includes two
> of the levels of the categorical vector and do the plot again, all three
> levels are still shown on the x-axis even though one of them doesn't exist
> in the dataset. The plot shows correct number of boxes (2).
>
> The whole syntax for what I describe is as follows:
> exploration.df <- read.table('clipboard', header=T)
> attach(exploration.df)
> plot(treatment,total.escapes)
>
> exp.df <- subset(exploration.df, treatment!='up')
> attach(exp.df)
> plot(treatment, total.escapes)
>
> I use R version 2.9.1 (2009-06-26) for Debian.
>
> Knut Helge Jensen
>
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html<http://www.r-project.org/posting-guide.html>
> and provide commented, minimal, self-contained, reproducible code.
>
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.