Dear R Help, I have a set of data of heights of trees described by area that they are in. The areas are numerical (0 to 7). ht area 1 320 3 2 410 4 3 230 2 4 360 3 5 126 1 6 280 2 7 260 2 8 280 2 9 280 2 10 260 2 ....... 180 450 4 181 90 1 182 120 1 183 440 4 184 210 2 185 330 3 186 210 2 187 100 1 188 0 0 I want to convert the area column values to factors, to do an anova. However, if I use: df$areaf <- factor(df$area, labels=c("0","I","II","III","IV","V","VI","VII")) it gives the following message: Error in factor(df$area, labels = c("0", "I", "II", "III", "IV", "V", "VI", : invalid labels; length 8 should be 1 or 7 Can anyone help? Jabez ___________________________________________________________ now. [[alternative HTML version deleted]]
Hi, df ht area 1 320 3 2 410 4 3 230 2 4 360 3 5 126 1 6 280 2 7 260 2 8 280 2 9 280 2 10 260 2 df$area <- as.factor(df$area) levels(df$area) <- c("I", "II", "III", "IV") -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O On 10/08/07, Jabez Wilson <jabezwuk@yahoo.co.uk> wrote:> > Dear R Help, > I have a set of data of heights of trees described by area that they are > in. The areas are numerical (0 to 7). > > ht area > 1 320 3 > 2 410 4 > 3 230 2 > 4 360 3 > 5 126 1 > 6 280 2 > 7 260 2 > 8 280 2 > 9 280 2 > 10 260 2 > ....... > 180 450 4 > 181 90 1 > 182 120 1 > 183 440 4 > 184 210 2 > 185 330 3 > 186 210 2 > 187 100 1 > 188 0 0 > > I want to convert the area column values to factors, to do an anova. > However, if I use: > > df$areaf <- factor(df$area, > labels=c("0","I","II","III","IV","V","VI","VII")) > > it gives the following message: > > Error in factor(df$area, labels = c("0", "I", "II", "III", "IV", "V", > "VI", : > invalid labels; length 8 should be 1 or 7 > > Can anyone help? > > Jabez > > > ___________________________________________________________ > > now. > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@stat.math.ethz.ch 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. >[[alternative HTML version deleted]]
Hi r-help-bounces at stat.math.ethz.ch napsal dne 10.08.2007 13:41:53:> Dear R Help, > I have a set of data of heights of trees described by area that they arein.> The areas are numerical (0 to 7). > > ht area > 1 320 3 > 2 410 4 > 3 230 2 > 4 360 3 > 5 126 1 > 6 280 2 > 7 260 2 > 8 280 2 > 9 280 2 > 10 260 2 > ....... > 180 450 4 > 181 90 1 > 182 120 1 > 183 440 4 > 184 210 2 > 185 330 3 > 186 210 2 > 187 100 1 > 188 0 0 > > I want to convert the area column values to factors, to do an anova.However, if I use:> > df$areaf <- factor(df$area,labels=c("0","I","II","III","IV","V","VI","VII"))> > it gives the following message: >Hm, maybe some of the values are missing> num<-sample(1:3, 10, replace=T) > num[1] 1 3 1 2 3 3 1 3 3 3> factor(num, labels=c("O", "I", "II"))[1] O II O I II II O II II II Levels: O I II> factor(num, labels=c("O", "I", "II", "III"))Error in factor(num, labels = c("O", "I", "II", "III")) : invalid labels; length 4 should be 1 or 3>try table(df$area) to see what level you really have Regards Petr> Error in factor(df$area, labels = c("0", "I", "II", "III", "IV", "V","VI", :> invalid labels; length 8 should be 1 or 7 > > Can anyone help? > > Jabez > > > ___________________________________________________________ > > now. > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code.
I am afraid the above example will not work. In original dataset of Jabez Wilson numerical range is from 0..7. So try this one: df<-as.factor(c("0","I","II","III","IV","V","VI","VII")[df$area+1]) Hope this is what you want, Rainer Henrique Dallazuanna schrieb:> Hi, > > df > ht area > 1 320 3 > 2 410 4 > 3 230 2 > 4 360 3 > 5 126 1 > 6 280 2 > 7 260 2 > 8 280 2 > 9 280 2 > 10 260 2 > > df$area <- as.factor(df$area) > levels(df$area) <- c("I", "II", "III", "IV")> > > On 10/08/07, Jabez Wilson <jabezwuk at yahoo.co.uk> wrote: >> Dear R Help, >> I have a set of data of heights of trees described by area that they >> are in. The areas are numerical (0 to 7). >> >> ht area >> 1 320 3 >> 2 410 4 >> 3 230 2 >> 4 360 3 >> 5 126 1 >> 6 280 2 >> 7 260 2 >> 8 280 2 >> 9 280 2 >> 10 260 2 >> ....... >> 180 450 4 >> 181 90 1 >> 182 120 1 >> 183 440 4 >> 184 210 2 >> 185 330 3 >> 186 210 2 >> 187 100 1 >> 188 0 0 >> >> I want to convert the area column values to factors, to do an anova. >> However, if I use: >> >> df$areaf <- factor(df$area, >> labels=c("0","I","II","III","IV","V","VI","VII")) >> >> it gives the following message: >> >> Error in factor(df$area, labels = c("0", "I", "II", "III", "IV", "V", >> "VI", : >> invalid labels; length 8 should be 1 or 7 >> >> Can anyone help? >> >> Jabez