I'm looking to perform operations for one column based on grouping for another column.
Say I have the following data:
user <- c(1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3)
score <- c(1, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1)
time_1 <- c(130, NA, 120, 245, NA, NA, NA, 841, NA, NA, 721, 612)
time_2 <- c(NA, 742, NA, NA, 812, 212, 214, NA, 919, 528, NA, NA)
df <- data.frame(user, score, time_1, time_2)
We get the following df:
user score time_1 time_2
1 1 130 NA
1 0 NA 742
1 1 120 NA
1 1 245 NA
2 0 NA 812
2 0 NA 212
2 0 NA 214
2 1 841 NA
3 0 NA 919
3 0 NA 528
3 1 721 NA
3 1 612 NA
For every user 1, what is the smallest value of time_1
?
So I am looking to group users by their number, and perform an operation on column time_1
.