[R] Building a what list for scan to use

Duncan Murdoch murdoch.duncan at gmail.com
Mon May 31 13:39:36 CEST 2010


On 31/05/2010 7:07 AM, Alex van der Spek wrote:
> Using read.table now on large files. Scan should be faster reading and 
> parsing the files if a 'what' list is provided.
>
> How would I generate a what list that repeats the the last 4 elements n 
> (n=14 or 10 or 8) times?
>
> whatlist=list(Tstamp="",Condition=0,A1=0,B1=0,C1=0,D1=0)
>
> All are numeric, either decimal or hexadecimal.
>
>   

Do it like this:

n <- 14
indices <- c(1,2, rep(3:6, n))
biglist <- whatlist[indices]


This repeats the names too; if you want new names for the repeated 
columns, you can reassign the names afterwards, e.g.

names(biglist) <- paste("name", 1:(2+4*n))

Duncan Murdoch



More information about the R-help mailing list