[R] How to delete repeated values in MCMC sampling and get index of unique values?
David Winsemius
dwinsemius at comcast.net
Thu Jan 17 23:09:19 CET 2013
On Jan 17, 2013, at 1:50 PM, C W wrote:
> Dear list,
> How do you delete repeated samples? In MCMC, when your candidate value has
> been reject, so you remain on the same point, so you keep that value.
>
> Say I have this toy example,
>
>> c(1,6,6,6,3,5,4,4,2,3,5)
> c(1,6,6,6,3,5,4,4,2,3,5)[!duplicated(c(1,6,6,6,3,5,4,4,2,3,5))]
[1] 1 6 3 5 4 2
> x <- c(1,6,6,6,3,5,4,4,2,3,5)
> x[!duplicated(x)]
[1] 1 6 3 5 4 2
> !duplicated(x)
[1] TRUE TRUE FALSE FALSE TRUE TRUE TRUE FALSE TRUE FALSE FALSE
> which(!duplicated(x))
[1] 1 2 5 6 7 9
>
> The 6 and 4 are repeated, I only want the index of the non-repeated values.
>
> I thought of using which() and unique(), but that does not give you the
> index of the unique values.
>
> Thanks in advance.
>
> Mike
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
David Winsemius
Alameda, CA, USA
More information about the R-help
mailing list