[R] R-devel not R-help (was "Bug? using { as a function ...")

"Jens Oehlschlägel" joehl at gmx.de
Wed Sep 29 18:46:26 CEST 2004


Gabor,

> The real problem is how to create a list with given names
> and constant content.  

When this is your problem to solve, why don't you do the following?

as.constlist <- function(content, names){
	content <- rep(list(content), length=length(names))
	names(content) <- names
	content
}
nams <- letters[1:3]
v <- 1:2
as.constlist(v, nams)


Best 


Jens Oehlschlägel


> I find I need to do that and when I noticed
> a recent problem posted on r-help that required it I decided it was 
> time that I figured out a better way to do it.  I simplified the 
> problem for purpose of bringing out the error more clearly but it
> otherwise does stem from a real problem.
> 
> To illustrate, we will use this test data:
> 
> 		 nams <- letters[1:3]
> 		 v <- 1:2
> 
> The following will do it:
> 
> 		 L <- rep(list(v), length(nams))
> 		 names(L) <- nams
> 
> but I wanted a more compact expression.

-- 
GMX ProMail mit bestem Virenschutz http://www.gmx.net/de/go/mail
+++ Empfehlung der Redaktion +++ Internet Professionell 10/04 +++




More information about the R-help mailing list