Re: [R] sampling rows with values never sampled before

2015-06-23 Thread Jon Skoien
If df is the data.frame with values and you want nn samples, then this is a slightly different approach: # example data.frame: df = data.frame(a1 = sample(1:20,50, replace = TRUE), a2 = sample(seq(0.1,10,length.out = 30),50, replace = TRUE),

Re: [R] sampling rows with values never sampled before

2015-06-22 Thread C W
Hi Jean, Thanks! Daniel, Yes, you are absolutely right. I want sampled vectors to be as different as possible. I added a little more to the earlier data set. x1 x2 x3 [1,] 1 3.7 2.1 [2,] 2 3.7 5.3 [3,] 3 3.7 6.2 [4,] 4 3.7 8.9 [5,] 5 3.7 4.1 [6,] 1 2.9 2.1 [7,] 2 2

Re: [R] sampling rows with values never sampled before

2015-06-22 Thread Daniel Nordlund
On 6/22/2015 9:42 AM, C W wrote: Hello R list, I am have question about sampling unique coordinate values. Here's how my data looks like dat <- cbind(x1 = rep(1:5, 3), x2 = rep(c(3.7, 2.9, 5.2), each=5)) dat x1 x2 [1,] 1 3.7 [2,] 2 3.7 [3,] 3 3.7 [4,] 4 3.7 [5,] 5 3.7

Re: [R] sampling rows with values never sampled before

2015-06-22 Thread Adams, Jean
Mike, There may be a more efficient way to do this, but this works on your example. # mix up the order of the rows mix <- dat[order(runif(dim(dat)[1])), ] # get rid of duplicate x1s and x2s sub <- mix[!duplicated(mix[, "x1"]) & !duplicated(mix[, "x2"]), ] sub Jean On Mon, Jun 22, 2015 at 11:42

[R] sampling rows with values never sampled before

2015-06-22 Thread C W
Hello R list, I am have question about sampling unique coordinate values. Here's how my data looks like > dat <- cbind(x1 = rep(1:5, 3), x2 = rep(c(3.7, 2.9, 5.2), each=5)) > dat x1 x2 [1,] 1 3.7 [2,] 2 3.7 [3,] 3 3.7 [4,] 4 3.7 [5,] 5 3.7 [6,] 1 2.9 [7,] 2 2.9 [8,] 3 2.9