[R] scan() with "what"

ripley@stats.ox.ac.uk ripley at stats.ox.ac.uk
Sat Dec 14 21:59:03 CET 2002


On Sun, 15 Dec 2002, Ko-Kang Kevin Wang wrote:

> 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.

Unlikely if you specify colClasses, which sets up calls to scan() for you.

> 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.

Try colClasses first.

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595




More information about the R-help mailing list