[R] sampling rows with values never sampled before

Adams, Jean
2015-06-22T17:09:43Z

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 AM, C W <tmrsg11 at gmail.com> 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
>  [6,]  1 2.9
>  [7,]  2 2.9
>  [8,]  3 2.9
>  [9,]  4 2.9
> [10,]  5 2.9
> [11,]  1 5.2
> [12,]  2 5.2
> [13,]  3 5.2
> [14,]  4 5.2
> [15,]  5 5.2
>
>
> If I sampled (1, 3.7), then, I don't want (1, 2.9) or (2, 3.7).
>
> I want to avoid either the first or second coordinate repeated.  It leads
> to undefined matrix inversion.
>
> I thought of using sampling(), but not sure about applying it to a data
> frame.
>
> Thanks in advance,
>
> Mike
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.