Did you actually test that purported solution? I get NA's, which is not surprising to me since the levels of chickwts$feed are character valued.
When I try as.numeric(chickwts$feed) I get the numeric values that I believe are being requested. The FAQ regarding conversion from an inadvertent input of a numeric as a factor implicitly assumes that the original values were digits rather than alpha. http://cran.r-project.org/doc/FAQ/R-FAQ.html#How-do-I-convert-factors-to-numeric_003f -- David Winsemius ----- Original Message ----- From: "Douglas Federman" <douglas.feder...@utoledo.edu> To: "schung" <stephanie.ch...@gmail.com>, r-help@r-project.org Sent: Wednesday, May 6, 2009 10:49:54 AM GMT -06:00 US/Canada Central Subject: Re: [R] changing variables in a dataset you could use chickwts$feed<- as.numeric(levels(chickwts$feed))[as.integer(chickwts$feed)] I got this by searching archives of old messages. I can't recall why the simpler as.numeric(chickwts$feed) is not an appropriate all around solution. -- "I like nonsense, it wakes up the brain cells. Fantasy is a necessary ingredient in living, it's a way of looking at life through the wrong end of a telescope. Which is what I do, and that enables you to laugh at life's realities." - Dr. Suess ________________________________ From: r-help-boun...@r-project.org on behalf of schung Sent: Wed 5/6/2009 10:55 AM To: r-help@r-project.org Subject: [R] changing variables in a dataset Hi! I just quasi-learned how to use R and I'm trying to change the feed from horsebean, linseed, etc to 1, 2, 3, etc The dataset I'm practicing on is pre-loaded in R data(chickwts) chickwts Any help is much appreciated!! Thank you!! -- View this message in context: http://www.nabble.com/changing-variables-in-a-dataset-tp23407765p23407765.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ 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. [[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. [[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.