[R] Dealing with factors ???

PIKAL Petr petr.pikal at precheza.cz
Fri Nov 16 09:37:02 CET 2012


Hi

Please include context.

Your "numbers" are not numbers. They are strings in csv file e.g. "1,200,300" and are converted to factors during reading. 

First do not convert them to factors by stringsAsfactors=FALSE option in read.table.

If you are sure that all commas are thousands separators (in my country comma is used as decimal point) you can do

as.numeric(paste(unlist(strsplit("1,200,300", ",")), collapse=""))

or

tonum <- fumction (x) as.numeric(paste(unlist(strsplit(x, ",")), collapse=""))

tonum(some column of values)

Regards
Petr

> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of eric
> Sent: Friday, November 16, 2012 3:19 AM
> To: r-help at r-project.org
> Subject: Re: [R] Dealing with factors ???
> 
> The table is much bigger than what was shown. I just displayed a few
> rows.
> Seems like there should be a better way that the approach you are
> proposing.
> What is also not clear to me is why the factors are coming at all. I do
> a read.csv on a table full of numbers from excel and I'm seeing factors
> everywhere.
> 
> 
> 
> --
> View this message in context: http://r.789695.n4.nabble.com/Dealing-
> with-factors-tp4649686p4649689.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 guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.




More information about the R-help mailing list