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

Quets Jan Jan.Quets at ua.ac.be
Fri Aug 26 14:55:02 CEST 2011


Thank you,

this is what I need!
________________________________________
Van: Adrian.Baddeley at csiro.au [Adrian.Baddeley at csiro.au]
Verzonden: vrijdag 26 augustus 2011 10:42
Aan: r-sig-geo at r-project.org
CC: Quets Jan; Adrian.Baddeley at csiro.au; r.turner at auckland.ac.nz
Onderwerp: [R-sig-Geo] using 'for loop' for assigning saved function values of function envelope in spatstsat

Jan Quets wrote:

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

> 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")$???
> }

According to `help(envelope)' in the package 'spatstat',

          If savefuns=TRUE, the return value has an attribute "simfuns"
          which is an object of class "fv" containing the summary functions
          computed for each of the nsim simulated patterns.

So if you do

          sf <- attr(env, "simfuns")

then 'sf' is an object of the class 'fv'.

If you look at help(fv) you'll see that an 'fv' object inherits the class 'data.frame'.
(To convert it to just a data frame, use as.data.frame.) The "$" operator uses the method for data frames, so typing sf$sim42 just means you're extracting the column named 'sim42' from the data frame 'sf'.

You want to extract several, selected, columns from 'sf' and store them as entries in a list. Suppose you want all the columns sim1, sim2, ...., sim999 but not the column labelled "r". Then do:

        df <- as.data.frame(sf)
        wantcolumns <- (names(df) != "r")
        subdf <- df[, wantcolumns]
        sims <- as.list(subdf)

Then sims[[i]] will be a vector containing the values of the i-th simulated function.

I'm not really sure what you're trying to do. It should be possible and easier to work with the data frame 'df' or 'subdf'

regards

Adrian Baddeley



More information about the R-sig-Geo mailing list