[R] Forcing variables types when using read.table

David Kane <David Kane a296180 at mica.fmr.com
Wed Jul 11 14:35:44 CEST 2001


Perhaps I am being thick, but I can not figure out how to force read.table to
treat as character something that "looks" numeric to it. Here is a simple example:

> version
         _                   
platform sparc-sun-solaris2.6
arch     sparc               
os       solaris2.6          
system   sparc, solaris2.6   
status                       
major    1                   
minor    3.0                 
year     2001                
month    06                  
day      22                  
language R                   
> file.show("temp.txt")
sedol,price
000312,47
071290,112

> read.table("temp.txt", header = TRUE, sep = ",")
  sedol price
1   312    47
2 71290   112
> read.table("temp.txt", header = TRUE, sep = ",", as.is = TRUE)
  sedol price
1   312    47
2 71290   112
> 

Note that "sedol" is really a character string (it is an international
identifier for stocks) while price is numeric. How can I get read.table to
create sedol as character (and therefore keep around the leading zeroes)? I
guess that I am looking for an option like "what" from scan . . .

Thanks,

Dave Kane 
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list