[Rsiena-help] Loop in "sienaDataCreate"

Ruth Ripley ruth at stats.ox.ac.uk
Fri Jun 22 12:15:30 CEST 2012


Dear Philippe,

Two apologies: first, I did not reply to the list and second, I omitted 
sep="" from the code. I repeat my reply (with the corrected code) below 
for others' benefit.

sienaDataCreate uses the name of the object unless you supply another 
name. The supplied name cannot be varied by using a character variable.

You could use something like

mydata.basic.model <- list();

for (i in c(1:5))
     {
     mycall <- paste("sienaDataCreate(peers", i, "=peers[[i]])", sep="")

mydata.basic.model[[i]] <- eval(parse(text=mycall))}

which should give peers1 ... as the names of the networks. ([[ does not 
work in this context but I doubt it is an important part of the name.)

The idea here is to create a character string that represents the 
function call you would like to execute, parse it to make it an 
expression rather than a character string and then eval it.

Regards,

Ruth

On 21/06/2012 17:50, Philippe Sulger wrote:
> Dear all
>
> I try to program a loop over 5 different networks. Therein I use
> "sienaDataCreate". E.g.:
>
> mydata.basic.model <- list();
>
> for (i in c(1:5))
>      {mydata.basic.model[[i]] <- sienaDataCreate(peers[[i]])}
>
> Where "peers" is defined/specified previously as a list over networks s.t.
>
> peers <- list()
>
> for (i in c(1:5))
>      {peers[[i]] <- sienaNet(
>                            array( c(peers.data.w1[[i]], peers.data.w2[[i]]),
>                            dim = c( dim(peers.data.w1[[i]])[1],
> dim(peers.data.w2[[i]])[1], 2)))}
>
> The latter loop works. The former loop does not work. That is,
> mydata.basic.model[[1]], for instance, gets "peers[[i]]" as dependent
> variable (instead of "peers[[1]]". The same for the other networks.
>
> But if I define the model-data separately for each network, i.e.,
>
> mydata.basic.model[[1]] <- sienaDataCreate(peers[[1]])
> mydata.basic.model[[2]] <- sienaDataCreate(peers[[2]])
>
> it works.
>
> What goes wrong?
>
> Thank you for your efforts.
>
> Best
> Philippe
>
>
> This body part will be downloaded on demand.
>




More information about the Rsiena-help mailing list