Does the following do what you want?
> d <- list() # empty list
> for(i in 1:8) if (i %% 2 == 0) {
newElement <- structure(list(i), names=LETTERS[i])
d <- c(d, newElement)
}
> str(d)
List of 4
$ B: int 2
$ D: int 4
$ F: int 6
$ H: int 8
Bill Dunlap
TIBCO Software
wdunlap tibco.c
Your explanation of the problem is unclear and your use of HTML formatting
corrupts your code examples.
One issue is your reference to a loop while showing no loop nor input nor
output. There is more than one construct for iterating in R. One problem you
may be encountering is that you cannot c
t;d"
#variable el
> el<-"a"
#result
> d[[el]]<-"whatever I want to put under name a"
> d
$a
[1] "whatever I want to put under name a"
$b
[1] "a"
$c
[1] "e"
$d
[1] "b"
$e
[1] "d"
Cheers
Petr
From: carol w
white [mailto:wht_...@yahoo.com]
Sent: Friday, June 05, 2015 11:51 AM
To: PIKAL Petr
Subject: Re: [R] building a list in a loop for (i in c("a","b")) best, On
Friday, June 5, 2015 11:36 AM, PIKAL Petr wrote: Hi
Can you please specify how loop without index shall be constructe
arol white [mailto:wht_...@yahoo.com]
Sent: Friday, June 05, 2015 11:51 AM
To: PIKAL Petr
Subject: Re: [R] building a list in a loop for (i in c("a","b")) best, On
Friday, June 5, 2015 11:36 AM, PIKAL Petr wrote: Hi
Can you please specify how loop without index shall be const
t(a=NULL, b=NULL)
for (i in c("a","b")) {
d[[i]]<-1:3
}
Cheers
Petr
From: carol white [mailto:wht_...@yahoo.com]
Sent: Friday, June 05, 2015 11:51 AM
To: PIKAL Petr
Subject: Re: [R] building a list in a loop
for (i in c("a","b"))
best,
On Friday, Jun
Hi
Can you please specify how loop without index shall be constructed? It is
rather new topic for me.
Petr
From: carol white [mailto:wht_...@yahoo.com]
Sent: Friday, June 05, 2015 11:21 AM
To: PIKAL Petr
Subject: Re: [R] building a list in a loop
also consider a loop without index (not like
rm(1)
fit<-lm(y~s)
d[[i]]<-fit
names(d)[i] <- paste(letters[round(mean(s))],i, sep="")
}
So my opinion is that the code for populating list is pretty general.
Petr
From: carol white [mailto:wht_...@yahoo.com]
Sent: Friday, June 05, 2015 11:18 AM
To: PIKAL Petr
Subject: Re: [R]
It might be an easy question but how to construct correctly a list in a loop?
The following doesn't work
before starting the loopd = NULL#in the loop, 1st iteration
d = list(d,c(1,2,3)d[[1]]
NULL
[[2]]
[1] 1 2 3#in the loop, 2nd iterationd=list(d,c(4,5,6)d
[[1]]
[[1]][[1]]
NULL
[[1]][[2]]
[1] 1
Nice.
Thanks!
-N
On 5/30/10 3:16 PM, jim holtman wrote:
> Let initialize Chain:
>
> Chain <- vector('list', 5)
> groups <- 1:5
> for(j in 1:1){
>
>for(g in groups){
>
>coef <- c(1,2,3,4,5,6,7,8,9,10) #would be actual MCMC samples
>
>Chain[[g]] <- rbind(Chain[[g]], coef)
Let initialize Chain:
Chain <- vector('list', 5)
groups <- 1:5
for(j in 1:1){
for(g in groups){
coef <- c(1,2,3,4,5,6,7,8,9,10) #would be actual MCMC samples
Chain[[g]] <- rbind(Chain[[g]], coef)
}
}
On Sun, May 30, 2010 at 6:05 PM, Noah Silverman wrote:
> That would
That would be great, except I just realized I made a typo when sending
my code.
I'm tracking 20 coefficents for 10 groups. So I need a "top" list of 10
groups. Then each of the 10,000 samples for each of the 20 coefficients.
It should be more like this:
for(j in 1:1){
for(g in groups)
Hello Noah,
Does this work for you?
Chain <- vector("list", 1)
for (j in 1:1){
coef <- c(1,2,3,4,5,6,7,8,9,10) #would be actual MCMC samples
Chain[[j]] <- rbind(Chain[[j]], coef)
If it does, this has the additional advantage that it tends to be
faster to initialize the list at siz
Hello,
I need to build a "list of lists"
We have 20 groups we are generating MCMC samples for. There are 10
coefficients, and 1 MCMC iterations.
I would like to store each iteration by-group in a list. My problem is
with the first iteration.
Here is a toy example:
Chain <- list()
for (j
14 matches
Mail list logo