Re: [R] Remove levels

2013-06-13 Thread David Carlson
Carlson Sent: Thursday, June 13, 2013 9:00 AM To: 'Shane Carey'; r-help@r-project.org Subject: Re: [R] Remove levels Works fine for me. Too bad you didn't include actual data: > set.seed(42) > DATA <- data.frame(UnitName_1=factor(sample(c("lake", "pond&q

Re: [R] Remove levels

2013-06-13 Thread arun
  95 97 47 54 86 14 88 8 99 35 ...  levels(DATA[,1]) #[1] "pond"  "river" A.K. - Original Message - From: David Carlson To: 'Shane Carey' ; r-help@r-project.org Cc: Sent: Thursday, June 13, 2013 10:00 AM Subject: Re: [R] Remove levels Works fine for me.

Re: [R] Remove levels

2013-06-13 Thread Alain Guillet
Hi, Without more information I guess your problem is that the level name still exists in the factor whereas it doesn't appear anymore in the factor. If so, try droplevels. Alain Guillet On 13/06/13 14:02, Shane Carey wrote: > I have a dataframe consisting of factors in one column. Im trying t

Re: [R] Remove levels

2013-06-13 Thread David Carlson
Works fine for me. Too bad you didn't include actual data: > set.seed(42) > DATA <- data.frame(UnitName_1=factor(sample(c("lake", "pond", "river"), + 15, replace=TRUE)), Var=sample.int(100, 15)) > DATA UnitName_1 Var 1 river 95 2 river 97 3lake 12 4 river 4

Re: [R] Remove levels

2013-06-13 Thread Jeff Newmiller
Please read the Posting Guide, which among other things points out that you should be posting in plain text format, not HTML (which tends to corrupt example R code). Then please explain why your problem is not addressed by the below referenced section of the R Inferno. You may need to read [1]

Re: [R] Remove levels

2013-06-13 Thread Shane Carey
Nope, but thanks On Thu, Jun 13, 2013 at 1:11 PM, Albin Blaschka < albin.blasc...@standortsanalyse.net> wrote: > > > Am 13.06.2013 14:02, schrieb Shane Carey: > > I have a dataframe consisting of factors in one column. Im trying to >> remove >> certain levels using the following code: >> toBeRe

Re: [R] Remove levels

2013-06-13 Thread Albin Blaschka
Am 13.06.2013 14:02, schrieb Shane Carey: I have a dataframe consisting of factors in one column. Im trying to remove certain levels using the following code: toBeRemoved1<-which(DATA$UnitName_1=="lake") DATA<-DATA[-toBeRemoved1,] However it will not remove the level "lake" Hello! Is this a

Re: [R] remove levels from a factor

2008-08-30 Thread Frank E Harrell Jr
Adrian Dusa wrote: Adrian Dusa gmail.com> writes: [...snip...] f[which(f %in% names(table(f))[table(f) >= 2]), drop=TRUE] [1] a a Levels: a Or, more simple: f[f %in% names(table(f))[table(f) >= 2], drop=TRUE] [1] a a Levels: a Adrian Also see the combine.levels function in the Hmisc pa

Re: [R] remove levels from a factor

2008-08-30 Thread Adrian Dusa
Adrian Dusa gmail.com> writes: > > [...snip...] > > f[which(f %in% names(table(f))[table(f) >= 2]), drop=TRUE] > [1] a a > Levels: a Or, more simple: > f[f %in% names(table(f))[table(f) >= 2], drop=TRUE] [1] a a Levels: a Adrian __ R-help@r-project.o

Re: [R] remove levels from a factor

2008-08-30 Thread Adrian Dusa
Yuan Jian yahoo.com> writes: > [...snip...] > > I want to remove level b because level b has less than 2. > > f > [1] a a > Levels: a > f[which(f %in% names(table(f))[table(f) >= 2]), drop=TRUE] [1] a a Levels: a HTH, Adrian __ R-help@r-project.or

Re: [R] remove levels from a factor

2008-08-29 Thread milton ruser
Hi Yuan, It is not ellegant, but may work for you.. f<-as.factor(c("a","b","a")) f.freq<-data.frame(table(f)) f.freq lower.freq<-2 f.freq.subset<-subset(f.freq,f.freq$Freq>=lower.freq) f.freq.subset f.selected<-f[f %in% f.freq.subset$f] f.selected<-factor(f.selected) f.selected Best wishes,