[R] How to change levels?

PIKAL Petr petr.pikal at precheza.cz
Thu Jan 17 08:07:31 CET 2013


Hi

or you can just call factor function after subsetting

newdata[,7] <- factor (newdata[,7])

Regards
Petr

> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Ista Zahn
> Sent: Wednesday, January 16, 2013 6:36 PM
> To: paladini
> Cc: r-help at r-project.org
> Subject: Re: [R] How to change levels?
> 
> Hi,
> 
> see ?droplevels and/or the "stringsAsFactors" section of ?options
> 
> Best,
> Ista
> 
> On Wed, Jan 16, 2013 at 4:56 AM, paladini <paladini at beuth-
> hochschule.de> wrote:
> > Hello!
> > I have got a dataframe with 10 columns and 100 rows. The seventh
> > column consists of a lot of country names.
> > When I use newdata=subset(data, data[, 7]=="United Kingdom"|data[,
> > 7]=="Germany") I get just the rows where the country name is UK or
> Germany.
> > But the level information doesn`t change. That means if I use
> > levels(newdata[,7]), I get:
> >
> >  [1] "Austria"                  "Belgium"
> >  [3] "Denmark"                  "Finland"
> >  [5] "France"                   "Germany"
> >  [7] "Spain"                    "Sweden"
> >  [9] "Switzerland"              "The Netherlands"
> >  [11] "United Kingdom"           "United States of America"
> > That leads to problems in the further data processing .
> >
> > How can I change the level information to the real levels of newdata?
> >
> > Thanking you in anticipation
> >
> > Claudia
> >
> > ______________________________________________
> > 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.



More information about the R-help mailing list