[R] lapply and use.names howto

Prof Brian Ripley ripley at stats.ox.ac.uk
Thu Feb 15 09:59:13 CET 2007


On Thu, 15 Feb 2007, Johannes Graumann wrote:

> How do I make R use the use.names option in a context like this:

What 'use.names option'?  sapply has a USE.NAMES argument, but lapply does 
not.

> lapply(data, function(x)(read.table(x,quote="",header=TRUE,sep="\t")),
> use.names=TRUE)

'data' is the name of an R function.  If say 'dd' were a character vector 
of file names you could do

res <- lapply(dd, function(x)(read.table(x,quote="",header=TRUE,sep="\t"))
names(res) <- dd

or even

sapply(dd, function(x)(read.table(x,quote="",header=TRUE,sep="\t"),
        simplify = FALSE)

which does the same thing.

-- 
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 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-help mailing list