Contango - 6 months ago 32

R Question

I have a tricky problem in R that I just can't seem to solve without resorting to a loop.

I start with a vector of timeDates:

`library(timeDate)`

dates <- timeDate(c("2014-01-01","2008-01-02","2008-01-03","2008-01-04"))

I would like to find the indexes of any dates in a preset blacklist:

`dateBlacklist <- timeDate(c("2008-01-02","2008-01-03"))`

The result would be something like:

`indexesOfBlacklistedDates <- c(2,3)`

Answer

An ugly solution:

```
indexesOfBlacklistedDates <- which(timeDate:::as.character.timeDate(dates) %in% timeDate:::as.character.timeDate(dateBlacklist))
```

Another, not so ugly, solution (similar to @agstudy's answer)

```
which(as.character(dates) %in% as.character(dateBlacklist))
```