I've been struggling with this problem, and decided to ask for some help after some fails..
Here is my problem, I want to divide these two vectors based on the day, for instance 2012-12-11 will be 3/17 and 2012-12-12 should be 0/7. However I can't seem to figure out how to do this..
> ili
2012-12-11 2012-12-13 2012-12-14 2012-12-17
3 6 7 1
> no.ili
2012-12-11 2012-12-12 2012-12-13 2012-12-14 2012-12-15 2012-12-16 2012-12-17
17 7 232 322 38 21 36
The last attempt was to loop over the two vectors and add the value or zero to a new vector however when I use %in%
it doesn't put the values in order (obviously) but if I use ==
it also doesn't work..
days.ili <- unique(one.three$timestamp)
days <- unique(one.week$timestamp)
ili.vec <- rep(0, length(days))
for (i in 1:length(days)) {
if (days.ili[i] %in% days) {
ili.vec[i] <- ili[i]
} else {
ili.vec[i] <- 0
}
}
I must be forgetting some thing since I'm not being able to see through this problem.. Can anyone give me any idea about the best way to achieve this in R?
Perhaps an option will be using merge
..