Skip to content
Prev 139104 / 398506 Next

How can I sample from a two-dimensional grid of points

you can still use sample(), e.g.,

n.grid <- 500
muA.grid <- seq(-4, 4, length = n.grid)
muB.grid <- seq(-4, 4, length = n.grid)

vals <- data.matrix(expand.grid(muA.grid, muB.grid))
mu.p <- dnorm(vals[, 1]) * dnorm(vals[, 2], sd = 0.5)
mu.p <- mu.p / sum(mu.p)

ind <- 1:nrow(vals)
samp.ind <- sample(ind, 1000, TRUE, mu.p)
mu <- vals[samp.ind, ]
head(mu, 10)


I hope it helps.

Best,
Dimitris

----
Dimitris Rizopoulos
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
     http://www.student.kuleuven.be/~m0390867/dimitris.htm

----- Original Message ----- 
From: "Gregory Gentlemen" <gregory_gentlemen at yahoo.ca>
To: <r-help at stat.math.ethz.ch>
Sent: Monday, March 10, 2008 3:32 PM
Subject: [R] How can I sample from a two-dimensional grid of points
Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm