s-news
[Top] [All Lists]

Re: creating arguments to list()

To: P.J.Wells@open.ac.uk
Subject: Re: creating arguments to list()
From: Leonid Gibiansky <lgibiansky@emmes.com>
Date: Wed, 22 May 2002 11:45:40 -0400
Cc: s-news@wubios.wustl.edu
In-reply-to: <5.1.0.14.2.20020522113141.01d81490@mcmail.cis.mcmaster.ca>
References: <F9D44AC0D89CD311B9E3000629385C40044DA063@marconi.open.ac.u k>
Sorry, it looks like I misunderstood your question. To do assignment, you
can use something like:

foo.1 <- 1
foo.2 <- 2
foo.3 <- 3
n <- 3
rr <- vector("list",n)
for (i in 1:n){
        rr[[i]] <- get(paste("foo",i,sep=".") )
}
rr

Leonid


At 11:34 AM 5/22/02 -0400, John Fox wrote:
>Dear Julian,
>
>Try something like
>
>         lapply(objects(regexpr='foo.?'), function(x) eval(parse(text=x)))
>
>(The syntax for objects() works a bit differently in different version of 
>S-PLUS, but your question implies that you already have the character 
>vector of names.)
>
>I hope that this helps,
>  John
>
>At 03:56 PM 5/22/2002 +0100, you wrote:
>>I'm trying to do something like
>>
>>foo.list <- list(foo.1, foo.2, ...., foo.n)
>>
>>where foo.n are n vectors
>>
>>There must be a more elegant way to create these n arguments than
>>laboriously typing in "foo.1"... "foo.n", but so far my attempts to deduce
>>this have only produced foo.list with character string elements "foo.n"
>>rather than the objects foo.n -- i.e. I get
>>
>> >foo.list
>>[[1]]:
>>"foo.1"
>>
>># etc. rather than
>>
>> >foo.list
>>[[1]]:
>>[1] # lots of numbers go here
>>
>>For the avoidance of doubt, I'm *not* interested in naming the elements of
>>foo.list -- i.e. I don't want
>>
>> >foo.list
>>$foo.1:
>>[1] # lots of numbers go here
>
>-----------------------------------------------------
>John Fox
>Department of Sociology
>McMaster University
>Hamilton, Ontario, Canada L8S 4M4
>email: jfox@mcmaster.ca
>phone: 905-525-9140x23604
>web: www.socsci.mcmaster.ca/jfox
>-----------------------------------------------------
>
>--------------------------------------------------------------------
>This message was distributed by s-news@lists.biostat.wustl.edu.  To
>unsubscribe send e-mail to s-news-request@lists.biostat.wustl.edu with
>the BODY of the message:  unsubscribe s-news
>

<Prev in Thread] Current Thread [Next in Thread>