[R] Randomized Points in space/ saving model results

R. Michael Weylandt michael.weylandt at gmail.com
Mon Oct 31 21:32:40 CET 2011


Comments inline:


On Mon, Oct 31, 2011 at 1:51 AM, magono <nroyal01 at gmail.com> wrote:
> Ok, to michael
> Looking over what you posted I'm thinking this is the way forward but my
> lack of experience using functions is getting in the way of accomplishing
> the task.  Examining the outputs into the functions and putting in my own
> info is giving me a headache.  Here's my thoughts at each step  marked with
> ``````-
>
>
> runif2d <- function(n = 100, xmin = 1, xmax = 2, ymin = 14, ymax = 15){
> ```````put in my bounding box coordinates above

I'm not sure what you mean -- I did put in your bounding coordinates....

>     stopifnot(all(xmax > xmin, ymax > min))
>     y <- runif(n, ymin, ymax)
>     x <- runif(n, xmin, xmax)
> ````````shall I enter the bounding box info again above in the y= and x= ?

Ibid

>     cbind(x,y) }
> `````Say I want to examine the resulting points created, how can I go about
> this?

You simply run the function and look at the output: i.e., copy and
paste my code into R and then type POINTS <- runif2d to make some
points and store them; then type POINTS again to see what they look
like. It will of course contain different points each time...

>
> getdist <- function(inpoints, refpoints) {
> ``````` which of these is my .csv of predetermined coordinates to add to the
> mix and which of these points to the generated points above?
>    # Takes in two 2 column matrices representing (x,y) coordinates
>    #   and returns a matrix with all the distance pairs between them
>       stopifnot(all(is.matrix(inpoints), is.matrix(refpoints),
> dim(inpoints)[2L] == 2L, dim(refpoints)[2L] == 2L))
>       d <- matrix(nrow = nrow(inpoints), ncol = nrow(refpoints))
>       for (i in seq_along(refpoints)) {
>             d[, i] <- rowSums(inpoints-refpoints[i,]^2)
>       }
>       d
> }
> `````Again, I want to see the matrix created above with all the points and
> distances, how do I call that up (I know this must be simple, but I think
> since I can't get the whole shabang to work, I'm having trouble finding the
> right command to look at the results.)

As explained above, just run the function: this code will handle everything.

Though it sounds like you might want to use the packages Rolf pointed
you towards: they are designed to do all this behind the scenes.

M

>
>
> Thanks so much by the way, you have an enviable command of R.
>
> -M.
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Randomized-Points-in-space-saving-model-results-tp3922612p3954873.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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.
>



More information about the R-help mailing list