[R] lapply and use.names howto

Johannes Graumann johannes_graumann at web.de
Thu Feb 15 10:06:37 CET 2007


Thanks a lot for opening my eyes.

Joh

Prof Brian Ripley wrote:

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



More information about the R-help mailing list