Displaying 1 result from an estimated 1 matches for "tosampl".
Did you mean:
tosample
2007 Aug 28
1
substituting elements in vector according to sample(unique(vector))
Hello!
Assuming I have a vector, such as
v <- c(1,2,1,2,3,3,1)
This vector has three unique elements: 1, 2, and 3.
> unique(v)
[1] 1 2 3
If I shuffle this vector of unique elements, I get something like this:
> sample(unique(v))
[1] 3 2 1
In the vector v I started with, I would now like to replace each element in
unique(v) with the corresponding element (i.e. the element with the