I am analyzing a dataset including a participants' ID number, which expresses each participant's unique ID
in a certain group (e.g., worker id, registered id, or whatever).
Because I would like to upload the dataset online, I need to provide different IDs for each participant. The dataset was shaped into a long data to analyze with a generalized linear mixed-effects model
(GLMM
) as follows:
I would like to replace the id
s, starting from 1.
The following is one potential resulting dataset I would like to obtain:
I have been trying to use pivot_longer
and pivot_wide
for hours, but could not figure out how to do this.
I would appreciate it if you could demonstrate how I can replace the id column with new ids.
Here are some replicable dataset:
structure(list(id = c(1001L, 1001L, 1001L, 1001L, 1001L, 1001L,
1001L, 1001L, 1001L, 1002L, 1002L), condition_a = c("a", "a",
"a", "b", "b", "b", "c", "c", "c", "a", "a"), condition_b = c("aa",
"aa", "aa", "aa", "aa", "aa", "aa", "aa", "aa", "bb", "bb"),
condition_c = c("abc", "abc", "abc", "abc", "abc", "abc",
"abc", "abc", "abc", "abc", "abc"), condition_d = c(10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 15L, 15L), items = c("a",
"b", "c", "d", "e", "f", "g", "h", "i", "a", "b"), response = c(0L,
1L, 0L, 1L, 0L, 1L, 0L, 1L, 0L, 1L, 0L)), class = "data.frame", row.names = c(NA,
-11L))