I have a df with two columns, ID and a character variable with "Y" and "N". I want to permute the second column 1000 times and assign a value to identify each permutation set. My end goal is to create a null distribution with the permutations.
boot <- transform(boot, column2 = sample(column2))
I have got this to work to make one permutation but I have struggled to loop this 1000 times and assign a value for each permutation.This also creates a new df each time which seems inefficient but I am relatively new to R so any suggestions will be very helpful.
Using tidyverse functions you can achieve this. Let's say you want 4 permutations for each id. You can get them in "long" and "wide" format.
Long
Wide
Here we pass the ids as column names
Created on 2021-06-22 by the reprex package (v2.0.0)