Chris Anderson
2009-Jul-01 19:43 UTC
[R] recoding charactor variables with special charactors
I have a several character variables that I need to recode, but some of them have special characters like single quote or ( ). How tell R to ignore these special characters so I can rename them? Below is the error message I am getting. social$FamilySupport[social$FamilySupport=="Mr. XXXs' extended family live in the Nashville area where he and his wife reside."]<-"Highly Supportive" Warning in `[<-.factor`(`*tmp*`, social$FamilySupport == "Mr. XXXs' extended family live in the Nashville area where he and his wife reside.", : invalid factor level, NAs generated Chris Anderson 707.315.8486 www.sassydeals4u.com ____________________________________________________________ Click to find deals on color printers and inks. http://thirdpartyoffers.netzero.net/TGL2241/fc/BLSrjpYR5fJC7MeC1xbOpWpulSKIYlbNvfa8G3h7se8nrP9RvM2utx3A3bK/ [[alternative HTML version deleted]]
Henrique Dallazuanna
2009-Jul-01 22:04 UTC
[R] recoding charactor variables with special charactors
It's because the levels of factor, don't characters: f <- factor(c("AAA's", "B(s)", "CCC")) levels(f)[levels(f) == "AAA's"] <- "AAAAAA" On Wed, Jul 1, 2009 at 4:43 PM, Chris Anderson <chris6764@netzero.net>wrote:> I have a several character variables that I need to recode, but some of > them have special characters like single quote or ( ). How tell R to ignore > these special characters so I can rename them? Below is the error message I > am getting. > > social$FamilySupport[social$FamilySupport=="Mr. XXXs' extended family live > in the Nashville area where he and his wife reside."]<-"Highly Supportive" > Warning in `[<-.factor`(`*tmp*`, social$FamilySupport == "Mr. XXXs' > extended family live in the Nashville area where he and his wife reside.", > : > invalid factor level, NAs generated > > > > Chris Anderson > 707.315.8486 > www.sassydeals4u.com > ____________________________________________________________ > Click to find deals on color printers and inks. > > http://thirdpartyoffers.netzero.net/TGL2241/fc/BLSrjpYR5fJC7MeC1xbOpWpulSKIYlbNvfa8G3h7se8nrP9RvM2utx3A3bK/ > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@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. >-- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O [[alternative HTML version deleted]]
First of all try str(socia) and see what the structure of the data is. R seems to be interpreting that character string as a format If I am reading the error message correctly. --- On Wed, 7/1/09, Chris Anderson <chris6764 at netzero.net> wrote:> From: Chris Anderson <chris6764 at netzero.net> > Subject: [R] recoding charactor variables with special charactors > To: r-help at r-project.org > Received: Wednesday, July 1, 2009, 3:43 PM > I have a several character variables > that I need to recode, but some of them have special > characters like single quote or ( ). How tell R to ignore > these special characters so I can rename them? Below is the > error message I am getting. > > social$FamilySupport[social$FamilySupport=="Mr. XXXs' > extended family live in the Nashville area where he and his > wife reside."]<-"Highly Supportive" > Warning in `[<-.factor`(`*tmp*`, social$FamilySupport => "Mr. XXXs' extended family live in the Nashville area where > he and his wife reside.",? : > ? invalid factor level, NAs generated > > > > Chris Anderson > 707.315.8486 > www.sassydeals4u.com > ____________________________________________________________ > Click to find deals on color printers and inks. > http://thirdpartyoffers.netzero.net/TGL2241/fc/BLSrjpYR5fJC7MeC1xbOpWpulSKIYlbNvfa8G3h7se8nrP9RvM2utx3A3bK/ > ??? [[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. >__________________________________________________________________ Make your browsing faster, safer, and easier with the new Internet Explorer? 8. Optimized for Yahoo! Get it N