Good Day, I have a small question, I think it is simple to solve, I have a column with the following records name saucer cup tea saucer saucer what is the quickest way to create a new column codes 1 1 3 1 1 -- View this message in context: http://r.789695.n4.nabble.com/Column-with-codes-tp4452906p4452906.html Sent from the R help mailing list archive at Nabble.com.
Hi> Good Day, > > I have a small question, I think it is simple to solve, > > I have a column with the following records > > name > saucer > cup > tea > saucer > saucer > > what is the quickest way to create a new column codes > 1 > 1 > 3 > 1 > 1Those numbers does not correspond to above mentioned names. If they should and the.variable is factor as.numeric(the.variable) produces underlaying numeric values. Regards Petr> > > -- > View this message in context: http://r.789695.n4.nabble.com/Column-with- > codes-tp4452906p4452906.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org 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.
On 07-03-2012, at 12:09, RMSOPS wrote:> Good Day, > > I have a small question, I think it is simple to solve, > > I have a column with the following records > > name > saucer > cup > tea > saucer > saucer >I assume that name is a column header. Otherwise the following makes no sense.> what is the quickest way to create a new column codes > 1 > 1 > 3 > 1 > 1I assume that the second 1 here is actually intended to be a 2. Maybe: as.numeric(factor(x,levels=(c("saucer","cup","tea")))) Berend
It was. Thanks -- View this message in context: http://r.789695.n4.nabble.com/Column-with-codes-tp4452906p4453124.html Sent from the R help mailing list archive at Nabble.com.
On Mar 7, 2012, at 7:11 AM, Berend Hasselman wrote:> > On 07-03-2012, at 12:09, RMSOPS wrote: > >> Good Day, >> >> I have a small question, I think it is simple to solve, >> >> I have a column with the following records >> >> name >> saucer >> cup >> tea >> saucer >> saucer >> > > I assume that name is a column header. Otherwise the following makes > no sense. > >> what is the quickest way to create a new column codes >> 1 >> 1 >> 3 >> 1 >> 1 > > I assume that the second 1 here is actually intended to be a 2. > > Maybe: > > as.numeric(factor(x,levels=(c("saucer","cup","tea"))))Oh, what the heck. I will add yet a third guess .... that you wanted: table(name) -- David Winsemius, MD West Hartford, CT