Re: [R] levels in dataframes

From: Peter Alspach <PAlspach_at_hortresearch.co.nz>
Date: Wed, 23 Apr 2008 09:17:48 +1200

Georg

One way is to call factor() on the subsetted object.

> georg <- factor(LETTERS[1:4])
> summary(georg)

A B C D
1 1 1 1
> georg <- georg[georg!='A']
> summary(georg) # the level is still there
A B C D
0 1 1 1
> georg <- factor(georg)
> summary(georg) # now it is gone

B C D
1 1 1

HTH .... Peter Alspach  

> -----Original Message-----
> From: r-help-bounces_at_r-project.org
> [mailto:r-help-bounces_at_r-project.org] On Behalf Of Georg Ehret
> Sent: Wednesday, 23 April 2008 8:58 a.m.
> To: r-help
> Subject: [R] levels in dataframes
>
> Dear R community, I wish to ask a short question
> concerning factor-data
> in dataframes: When I subset the data and get rid of all data
> for one level, I still retain the level name (obtained by
> levels(dataframe$variablename) ).
> Is there a convenient way to get rid of the levels for which
> all data has been deleted?
> Thank you and wishing you an excellent day!
> Georg.
> ****************************************************
> Georg Ehret
> Johns Hopkins
> Baltimore, US
>
> [[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.
>

The contents of this e-mail are privileged and/or confidential to the named  recipient and are not to be used by any other person and/or organisation.  If you have received this e-mail in error, please notify the sender and delete  all material pertaining to this e-mail.



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 Tue 22 Apr 2008 - 21:31:30 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 Tue 22 Apr 2008 - 22:30:32 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