Re: [R] transforming character categories

2009-06-28 Thread Gabor Grothendieck
Or use the labels= argument of factor. On Sun, Jun 28, 2009 at 8:06 AM, Peter Dalgaard wrote: > Gabor Grothendieck wrote: >> >> If you only want to convert them to unique numbers then >> >> as.numeric(factor(x)) >> >> will do that. > > Or, use it directly for indexing, as in c(1000,2500,4173,3700)

Re: [R] transforming character categories

2009-06-28 Thread Peter Dalgaard
Gabor Grothendieck wrote: If you only want to convert them to unique numbers then as.numeric(factor(x)) will do that. Or, use it directly for indexing, as in c(1000,2500,4173,3700)[factor(x)] DEPENDING on LEVEL ORDER, mind you! So make sure you know what the order is or set it yourself usin

Re: [R] transforming character categories

2009-06-28 Thread Gabor Grothendieck
If you only want to convert them to unique numbers then as.numeric(factor(x)) will do that. On Sun, Jun 28, 2009 at 7:00 AM, Gregor Povh wrote: > Thanks Gabor, but in my case not every value ist actually encoded within > the character string.  Vor example, I have an answer category, which is > "

Re: [R] transforming character categories

2009-06-28 Thread Gregor Povh
Thanks Gabor, but in my case not every value ist actually encoded within the character string. Vor example, I have an answer category, which is "more than one Mio. $". (not in the column "income"...). I have the feeling, that there must be an another, straightforward way or function for tran

Re: [R] transforming character categories

2009-06-28 Thread Gabor Grothendieck
Try this. It matches the first numeric string on each line applying as.numeric to it and then using c to simplify the resulting list to a numeric vector. > x <- c("from 1000$ to 2000$", "from 2000$ to 3000$", "more than 3000$", + "from 1000$ to 2000$", "from 1000$ to 2000$") > library(gsubfn) >

[R] transforming character categories

2009-06-28 Thread Gregor Povh
Dear R users, apologies for this quite simple question. I've tried serverall approaches, however, could not generate the desired result. I have a large data frame, which has several cathegories encoded as character strings, for example. Name, income, gender, ... ... "from 1000$ to 2000$