[R] read columns of quoted numbers as factors

Bernardo Rangel Tura tura at centroin.com.br
Tue Oct 5 11:20:01 CEST 2010


On Mon, 2010-10-04 at 09:39 -0700, james hirschorn wrote:
> Suppose I have a data file (possibly with a huge number of columns), where the 
> columns with factors are coded as "1", "2", "3", etc ... The default behavior of 
> read.table is to convert these columns to integer vectors. 
> 
> Is there a way to get read.table to recognize that columns of quoted numbers 
> represent factors (while unquoted numbers are interpreted as integers), without 
> explicitly setting them with colClasses ?
> 
> ______________________________________________
> 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.


Hi James,

I think you solve ypur problem using the options colClasses in the
read.table command, something like this

rea.table('name.of.table',colClasses=c(rep(30,'integer'),rep(5,'numeric'),etc))
-- 
Bernardo Rangel Tura, M.D,MPH,Ph.D
National Institute of Cardiology
Brazil



More information about the R-help mailing list