That's exactly what I want! For some reason, probably me missing something obvious, it's not working when I switch in some of the variable names in what you wrote to those matching my original code.
My data is first read in as a .csv using read.csv() and named Level. We are looking at performance at different levels of several behavioral tasks in a psychology experiment.
Then I go through the following:
####There are sixteen levels, so I'm filtering for rows that have one of these levels to remove practice trials and instruction screens. All of the participants' IDs start with "participant" and then have a number. We have several tester IDs so the next piece is removing the tester data.
Level1 <- Level %>% filter(level %in% c(1:16)) %>% filter(str_detect(username, "^p"))
####After this I go through and change the IDs into something more R-friendly.
NewID <- data.frame(ID = c(Level1$subject_id),
stringsAsFactors = FALSE)
summary(NewID)
range(NewID)
NewID$ID <- factor(NewID$ID)
Level2 <- cbind(NewID, Level1)
####Standardize Session ID. This is where I added in the code that you wrote, which looks like it should work perfectly. I changed some names to match what they are in my data.
MinSession <- Level2 %>% group_by(ID) %>% summarize(MinSess = min(session_id))
####R is returning only one observation of one variable. So I did not get to check the remaining code that you wrote, but I adjusted it for consistency.
DF <- inner_join(Level2, MinSession, by = "ID")
DF <- DF %>% mutate(AdjSession = session_id - MinSess + 1)
####Is it possible that something in my original data frame setup is responsible for this? Did I make some kind of obvious mistake changing the names?