1

I have a tibble of participant data from an experiment, and I need to replace a column of identifiable IDs with a new column of anonymous IDs. I have found the ids package which can generate random IDs for me, but I'm not sure how to do this so that they match up with the existing ones.

Specifically, each participant has multiple rows in the tibble (but not always the same number of rows per participant), so I need to insert a column of random IDs such that all of e.g. Bob's rows will get the ID 123, and all of Alice's rows will get the ID 456.

I was assuming it might be best to do this with apply, but I'm just not sure what the function should be so that I don't get a different random ID for every row.

data$randomID <- apply(data, 1, function(x) {random_id(bytes=5)} )
shleen
  • 19
  • 4

1 Answers1

0
data$randomID <- as.integer(factor(data$ID, levels = unique(data$ID)))
user438383
  • 5,716
  • 8
  • 28
  • 43
hello_friend
  • 5,682
  • 1
  • 11
  • 15