I am checking for duplicate dates in a data set with the following command:
duplicateTest <- duplicated(index(closePricesClean))
The output for this is a “FALSE” for every date not duplicated. So, if closePricesClean has 500 observations, then duplicateTest will return a list of 500 “TRUE” or “FALSE” values. What I’d like instead is to return a single “FALSE” value if the entire vector is “FALSE” or “TRUE” if the list contains even one “TRUE” value.
Do I need to construct an if statement? Or is there a function that I don’t know about?
Use
anyDuplicatedand check whether or not its result equals zero. This will be faster than usinganyon the results ofduplicatedbecause it will stop as soon as the firstTRUEis encountered.