[R] colClasses
Peter Dalgaard
p.dalgaard at biostat.ku.dk
Mon Oct 11 22:42:27 CEST 2004
"Kalaylioglu, Zeynep (IMS)" <KalayliogluZ at imsweb.com> writes:
> Hi
> I am trying to read a data frame from a text editor in to R. I want some
> of the columns to be read in as "character" not numeric.
> I figured that I can do that by using "colClasses" in "read.table"
> command. However, I couldn't find out how to use
> "colClasses". e.g. say I have 5 column in the data file. I want 1st and
> 3rd column to be read in as character. How can I define
> this using colClasses? (or is there a better way to do what I want?)
The easiest is probably
read.table(....as.is=c(1,3)....)
but you could also do
cC <- rep(NA,5)
cC[c(1,3)] <- "character"
read.table(....colClasses=cC...)
which would be more readily generalized to "stranger" data types.
--
O__ ---- Peter Dalgaard Blegdamsvej 3
c/ /'_ --- Dept. of Biostatistics 2200 Cph. N
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
More information about the R-help
mailing list