I am trying to create a unique, randomly assigned (without replacement) group id without using a for loop. This is as far as I got:
library(datasets)
library(dplyr)
data(iris)
iris <- iris %>% group_by(Species) %>% mutate(id = cur_group_id())
This gives me a group id for each iris$Species, however, I would like the group id to randomly assigned from c(1,2,3) as opposed to assigned based on the order of the dataset.
Any help creating this would be very helpful! I am sure there is a way to do this with dplyr but I am stumped...