[R] Forcing variables types when using read.table

About this list Date view Thread view Subject view Author view Attachment view

From: David Kane a296180@mica.fmr.com)
Date: Wed 11 Jul 2001 - 22:35:44 EST


Message-id: <15180.18464.584605.914004@gargle.gargle.HOWL>

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@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


About this list Date view Thread view Subject view Author view Attachment view

This archive was generated by hypermail 2.1.3 : Wed 10 Mar 2004 - 08:18:19 EST