[R-sig-Geo] using 'for loop' for assigning saved function values of function envelope in spatstsat

Quets Jan Jan.Quets at ua.ac.be
Wed Aug 24 18:58:42 CEST 2011


env is an object created with the function envelope in spatstat.

env has an attribute "simfuns" which you can "see" by typing:

attr(env,"simfuns")

this attribute of envelope is in itself a list (or whatever it is called?) of (in this case) 99 vectors

the first vector you can access by typing:

attr(env,"simfuns")$sim1

the 39th one (for example) by

attr(env,"simfuns")$sim39

let's say I create a list named 'a' with of the five first vectors of attr(env,"simfuns"). I do this like this:

A=list()

A[1][[1]] = attr(env,"simfuns")$sim1
A[2][[1]] = attr(env,"simfuns")$sim2
A[3][[1]] = attr(env,"simfuns")$sim3
A[4][[1]] = attr(env,"simfuns")$sim4
A[5][[1]] = attr(env,"simfuns")$sim5


However this is a rather cumbersome way to assign these vectors to list A, especially if there are much more vectors in attr(env,"simfuns") to assign to list A (in this case 99).

a for loop would be the right tool to do this, but I don't know how to do because the code below didn't work:

B=list()

for (i in 1:99){
B[i][[1]]=paste("sim",i,sep="")
}

for (i in 1:99){
A[i][[1]] = attr(env,"simfuns")$B[i][[1]]
}

I hope it is more clear now,

Thank you!

________________________________________
Van: romunov at gmail.com [romunov at gmail.com] namens Roman Luštrik [roman.lustrik at gmail.com]
Verzonden: woensdag 24 augustus 2011 18:03
Aan: Quets Jan
CC: r-sig-geo at r-project.org
Onderwerp: Re: [R-sig-Geo] using 'for loop' for assigning saved function values of function envelope in spatstsat

You can try paste and "[" (or "[[", depends on your needs).

x <- list(sim = 1:3)
x[paste("sim", 1, sep = "")]

Cheers,
Roman

p.s.
What you're trying to do seems a bit "hacky". What exactly are you trying to achieve, maybe there's a more elegant solution?





On Wed, Aug 24, 2011 at 5:15 PM, Quets Jan <Jan.Quets at ua.ac.be<mailto:Jan.Quets at ua.ac.be>> wrote:
Hello I would like to put the code at the end of the mail in a for loop like:

for (i in 1:999){
 sims[i][[1]] = attr(env,"simfuns")$???
}

This is obviously not a problem for the left side of the equations.
However I have no clue what should replace the sim1, sim2, ..., sim999
creating and using a list of strings with objects the strings 'sim1', 'sim2',..., 'sim999' does not work.

env is a envelope from spatstat where the argument 'savefuns' is set to 'TRUE'

Anyone an idea how to do this?

Thanks,
Jan

sims=list()
sims[1][[1]] = attr(env,"simfuns")$sim1
sims[2][[1]] = attr(env,"simfuns")$sim2
sims[3][[1]] = attr(env,"simfuns")$sim3
sims[4][[1]] = attr(env,"simfuns")$sim4
sims[5][[1]] = attr(env,"simfuns")$sim5
sims[6][[1]] = attr(env,"simfuns")$sim6
sims[7][[1]] = attr(env,"simfuns")$sim7
sims[8][[1]] = attr(env,"simfuns")$sim8
sims[9][[1]] = attr(env,"simfuns")$sim9
sims[10][[1]] = attr(env,"simfuns")$sim10

. . .

sims[999][[1]]=attr(env,"simfuns")$sim999
_______________________________________________
R-sig-Geo mailing list
R-sig-Geo at r-project.org<mailto:R-sig-Geo at r-project.org>
https://stat.ethz.ch/mailman/listinfo/r-sig-geo



--
In God we trust, all others bring data.



More information about the R-sig-Geo mailing list