This probably has a really simply solution. I have two data sets. One is a vector of POSIXct tweet timestamps and the second is a vector of POSIXct ADL HEAT Map timestamps.
I'm looking to build a function that lets me take the dates from the tweets vector and for each one count the number of timestamps in the ADL HEAT Map vector that fall within a specified range from the tweet.
My aim is to build the function such that I can put in the tweets vector, the ADL vector, the number of days from the tweets vector to start counting, and the number of days from the tweets vector to stop counting, and return a vector of counts the same length as the tweets data.
I already tried the solution here, and it didn't work: Count number of occurences in date range in R
Here's an example of what I'm trying to do. Here's a smaller version of the data sets I'm using:
tweets <- c("2016-12-12 14:34:00 GMT", "2016-12-5 17:20:06 GMT")
ADLData <- c("2016-12-11 16:30:00 GMT", "2016-12-7 18:00:00 GMT", "2016-12-2 09:10:00 GMT")
I want to create a function, let's call it countingfunction
that lets me input the first data set, the second one, and call a number of days to look back. In this example, I chose 7 days:
countingfunction(tweets, ADLData, 7)
Ideally this would return a vector of the length of tweets
or in this case 2 with counts for each of how many events in ADLData
occurred within the past 7 days from the date in tweets
. In this case, c(2,1)
.