My data looks like this:
data <- matrix(c("1","install","2015-10-23 14:07:20.000000",
"2","install","2015-10-23 14:08:20.000000",
"3","install","2015-10-23 14:07:25.000000",
"3","sale","2015-10-23 14:08:20.000000",
"4","install","2015-10-23 14:07:20.000000",
"4","sale","2015-10-23 14:09:20.000000",
"4","sale","2015-10-23 14:11:20.000000"),
ncol=3, byrow=TRUE)
colnames(data) <- c("id","event","time")
I would like to add a fourth column called label, in which I put each row accordingly on some values. In this case:
- label "0" if the identifier is unique
- label "1" if the identifier is not unique and is associated with 1 sale
- label "2" if the identifier is not unique and is associated with two sales
etc. up to n sales.
It should look like this:
data1 <- matrix(c("1","install","2015-10-23 14:07:20.000000","0",
"2","install","2015-10-23 14:08:20.000000","0",
"3","install","2015-10-23 14:07:25.000000","1",
"3","sale","2015-10-23 14:08:20.000000","1",
"4","install","2015-10-23 14:07:20.000000","2",
"4","sale","2015-10-23 14:09:20.000000","2",
"4","sale","2015-10-23 14:11:20.000000","2"),
ncol=4, byrow=TRUE)
I donβt understand what the best approach in R is to create βtagsβ based on conditions ... maybe dplyr::mutate?