Let's say I have data frame with two variables and 213005 observations, it looks like that:
df <- data.frame(nr=c(233, 233, 232, 231, 234, 234, 205),
date=c("2012/01/02", "2012/01/01", "2012/01/01", "2012/01/02", "2012/01/01", "2012/01/01", "2012/01/05"))
I need to create a new column called "new" for each different "nr" value according to "date" value, it should look like this:
df <- data.frame(nr=c(233, 233, 232, 231, 234, 234, 205),
date=c("2012/01/02", "2012/01/01", "2012/01/01", "2012/01/02",
"2012/01/01", "2012/01/01", "2012/01/05"),
new=c(1, 2, 3, 4, 5, 5, 6))
(nr=233, date=2012/01/02) => (new=1)
(nr=233, date=2012/01/01) => (new=2) ...
for (nr=234, date=2012/01/01) there should be two the same columns with new=5, repeated lines should stay in data frame.
Does anyone knows how to do that? Any help would be very appreciated! Thank you!