[R] scan() with "what"

Ken Lee ken_lee at tynesys.com
Mon Dec 16 06:51:03 CET 2002


Dear,
   coltypes<-rep("character(0)",25)
   x<-scan(file,what=noquote(as.list(coltypes)),sep=",",quiet=TRUE,skip=1)
   names(x)<-scan(file,what="",nlines=1, sep=",") 
   x<-as.data.frame(x)

  I hope it can help you.

Ken

     

-----Original Message-----
From: r-help-admin at stat.math.ethz.ch [mailto:r-help-admin at stat.math.ethz.ch]On Behalf Of Ko-Kang Kevin Wang
Sent: Sunday, December 15, 2002 4:45 AM
To: R Help
Subject: [R] scan() with "what"


Hi,

I have a medium-sized (19MB) CSV file that I'd like to read into R.  The
read.csv() function seems to be a bit inefficient to deal with it, and I
remember that using scan() with "what" options is better.

However I'm unable to understand how to use it.  The first few lines of
the data look like:

USAGE,MILEAGE,SEX,EXCESS,NCD,PRIMAGE,MINAGE,DRIVERS,DISTRICT,CARGROUP,CAR_AGE,WSCLMS,ADCLMS,FTCLMS,PDCLMS,PICLMS,ADINCUR,PDINCUR,WSINCUR,FTINCUR,PIINCUR,RECORD,DAYS,MINAGEN,PRIMAGEN
  SC,7000,M,100,4,59,25,3,4,7,6,0,0,0,,,0,,0,0,,1,85,25,59
  SC,7000,M,100,4,59,59,2,4,13,5,0,0,0,,,0,,0,0,,2,278,59,59
  SC,7000,M,100,4,60,60,2,4,13,5,0,0,0,,,0,,0,0,,3,364,60,60
  SB,10000,M,75,4,53,44,2,3,14,4,1,0,0,0,0,0,0,146.18,0,0,4,364,44,53
  SB,10000,M,75,4,54,45,2,3,14,4,0,0,0,,,0,,0,0,,5,363,45,54

i.e. columns are separated by commas and may contain missing values, and
has headers.

I'd really appreciated it if someone can tell me how to use the
scan() command to read this data in.

Cheers,

Kevin

------------------------------------------------------------------------------
/* Time is the greatest teacher, unfortunately it kills its students */

Ko-Kang Kevin Wang
Master of Science (MSc) Student
Department of Statistics
University of Auckland
New Zealand
Homepage: http://www.stat.auckland.ac.nz/~kwan022

______________________________________________
R-help at stat.math.ethz.ch mailing list
http://www.stat.math.ethz.ch/mailman/listinfo/r-help




More information about the R-help mailing list