I have an R dataframe like this:
blogger; date; word
joe; 2016-11-19; ears
paul; 2017-04-02; dilapidated
joe; 2016-11-21; night
joe; 2016-11-20; girl
paul; 2017-04-01; crumpled
paul; 2017-04-03; bellow
I want to sort it first by blogger
and then by date
. Then, I want to add a column with line numbers per blogger.
I have this:
# make linenumbers
df <- df %>%
arrange(blogger,date) %>%
mutate(linenumber = row_number())
But this, obviously, does not start on linenumber 1 for each blogger. The output I get is:
blogger; date; word; linenumber
joe; 2016-11-19; ears; 1
joe; 2016-11-20; girl; 2
joe; 2016-11-21; night; 3
paul; 2017-04-01; crumpled; 4
paul; 2017-04-02; dilapidated; 5
paul; 2017-04-03; bellow; 6
But the output I want is:
blogger; date; word; linenumber
joe; 2016-11-19; ears; 1
joe; 2016-11-20; girl; 2
joe; 2016-11-21; night; 3
paul; 2017-04-01; crumpled; 1
paul; 2017-04-02; dilapidated; 2
paul; 2017-04-03; bellow; 3