[R] reason for error in small function?

jim holtman jholtman at gmail.com
Thu Oct 11 20:34:32 CEST 2007


You need to return the value from the function.  "rpoints" is local to
the function and not visible.

gen.rpoints <- function(events, poly, nsim){
rpoints <- array(0, dim=c(nrow(events),2,nsim))
 for (i in 1:nsim) {
   rpoints[, ,i] <- csr(poly, nrow(events))
 }
 rpoints
}

rpoints <- gen.rpoints(events, poly, 99)


On 10/11/07, Dale Steele <dale.w.steele at gmail.com> wrote:
> Running the function below, tested using the cardiff dataset from
> splancs generates the following error.   What changes do I need to
> make to get the function to work?  Thanks.  --Dale
>
> > gen.rpoints(events, poly, 99)
> > rpoints
> Error: object "rpoints" not found
>
> # test spatial data
> library(splancs)
> data(cardiff)
> attach(cardiff)
> str(cardiff)
> events <- as.points(x,y)
>
> ### non-working function ####
>
> gen.rpoints <- function(events, poly, nsim){
> rpoints <- array(0, dim=c(nrow(events),2,nsim))
>  for (i in 1:nsim) {
>    rpoints[, ,i] <- csr(poly, nrow(events))
>  }
> }
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>


-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?



More information about the R-help mailing list