My data looks like this:
Subject Time Duration 
1       0.1s   0.006
1       0.5s   0
1       1s     0.733
..
2       0.3s   0
2       0.5s   0.553
2       2s     0.344
..
I want to order variable Duration according to variable Time for each Subject, excluding the 0 values.
I want to create an additional ordinal number ID variable, which will be ordered according to Time. So that my data looks like this:
Subject Time Duration ID
1       0.1s   0.006  1
1       0.5s   0      NA
1       1s     0.733  2
..
2       0.3s   0      NA
2       0.5s   0.553  1
2       2s     0.344  2
..
I tried dplyr::mutate(dataframe1, ID = row_number())
but I don't know how to mutate for every subject and how to exclude 0 or NA values in Duration variable.
Could anyone help me solve the problem?
Thank you.
 
    