Re: [R] Changing factor to numeric

2009-03-10 Thread Tal Galili
By the way, it could be that one of your numbers has "space" in them. in which case, R tends to turn the entire vector into a factor. try opening the file in a spreadsheet like excel, and do "search replace" on " " with "". and see how many it catches. Tal On Tue, Mar 10, 2009 at 7:25 AM, oj

Re: [R] Changing factor to numeric

2009-03-10 Thread Gabor Grothendieck
If you don't need any factors use read.csv(...whatever..., as.is = TRUE) and then as.numeric will work. On Tue, Mar 10, 2009 at 1:25 AM, ojal john owino wrote: > Dear Users, > I have a variable in my dataset which is of type factor. But it actually > contains numeric entries which like 5.735  4.7

Re: [R] Changing factor to numeric

2009-03-10 Thread milton ruser
Hi Ojal, I don't know why it happens, but try as.numeric(as.character(XXX)) Good luck miltinho astronauta brazil On Tue, Mar 10, 2009 at 1:25 AM, ojal john owino < ojal.johnow...@googlemail.com> wrote: > Dear Users, > I have a variable in my dataset which is of type factor. But it actually >

Re: [R] Changing factor to numeric

2009-03-10 Thread Mike Lawrence
Try: as.numeric(as.character(x)) I usually define the following for this purpose: factor.to.number=function(x){ as.numeric(as.character(x)) } On Tue, Mar 10, 2009 at 2:25 AM, ojal john owino wrote: > Dear Users, > I have a variable in my dataset which is of type factor. But it actually > conta

Re: [R] Changing factor to numeric

2009-03-10 Thread Krzysztof Sakrejda-Leavitt
If the real problem is that R reads your data file and converts everything it can into factors try including stringsAsFactors=FALSE in your read.table (or similar) statement. I run into this often enough that I set it as an option (I think it's: options(stringsAsFactors=FALSE). Then you can do

Re: [R] Changing factor to numeric

2009-03-10 Thread Uwe Ligges
From ?factor: The interpretation of a factor depends on both the codes and the "levels" attribute. Be careful only to compare factors with the same set of levels (in the same order). In particular, as.numeric applied to a factor is meaningless, and may happen by implicit coercion. To transform