Last active
April 10, 2017 12:16
-
-
Save b-rodrigues/a119949bcb94bcafc0f4eecdf95b914a to your computer and use it in GitHub Desktop.
Create a "counter" variable that gets incremented by one for each occurence of interest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(dplyr) | |
data("iris") | |
# At the first occurence of, say, Petal.Length = 1 and Petal.Width = 1, counter = 1. If Petal.Length = 1 and Petal.Width = 1 occur | |
# again, counter gets incremented to 2 | |
iris %>% | |
group_by(Petal.Length, Petal.Width) %>% | |
mutate(counter = seq_along(Species)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment