Re: [R] factor with numeric names

From: agent dunham <>
Date: Fri, 25 Mar 2011 02:31:55 -0700 (PDT)

Dear all,

According to the post I was trying:

factorA = c(2,2,3,3,4,4,3,4,2,2)
levels(factor <- c("lv1","lv2","lv3") )

But this returns NULL and doesn't change factor names.

Actually, my factor is included in a data.frame, so I also tried:

levels(df$factorA)[levels(df$factorA)=="2"] <- "lv1"  Also
levels(df$factorA)[levels(df$factorA)==2] <- "lv1"
levels(df$factorA)[levels(df$factorA)=="3"] <- "lv2"
levels(df$factorA)[levels(df$factorA)=="4"] <- "lv3"

then I type table(df$factorA) and it doesn't work either.

Any help would be appreciated. Thanks,

View this message in context:
Sent from the R help mailing list archive at

______________________________________________ mailing list
PLEASE do read the posting guide
and provide commented, minimal, self-contained, reproducible code.
Received on Fri 25 Mar 2011 - 13:07:38 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 Fri 25 Mar 2011 - 13:10:24 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive