Does anyone have any tips or useful functions for working with Neighborhood Patterns data in R?

Does anyone have any tips or useful functions for working with Neighborhood Patterns data in R? For instance, even trying to get stops_by_each_hour separated out at the date-time level vertically I’m struggling (same issue even if was trying to get stops_by_day). Something like:

Area Date time Visits
421010108001…4/1/2020 00:00:00 … 1
421010108001…4/1/2020 01:00:00 … 3
421010108001…4/1/2020 02:00:00 … 1
421010108001…4/1/2020 03:00:00 … 0

@Nick_H-K_Seattle_University would this be accomplished by the SafeGraphR package’s expand_integer_json() function?

Yep! expand_integer_json is the way to go.

Dang, I checked this like 3 times and convinced myself it didn’t apply. When I tried that, I get the error “Error: Argument ‘txt’ must be a JSON string, URL or file.” I’m sure a simple syntax error.
expand_integer_json(april2020, 'stops_by_each_hour', by = 'area'

Hmm, that’s odd, the syntax looks fine. Are there maybe weird additional quotes around the entries of stops_by_each_hour? Or non-numeric entries?

Stops_by_day also throws the same error. Thanks for all the help!

Hmm, that’s strange. I’ll take a look tonight

If useful, in trying to isolate/troubleshoot, it seems the “fromJSON” function used in your function is not reading the input as JSON for some reason. Even feeding it “fromJSON(april2020$stops_by_day[1])” I get the same error as above.

Converting the column to as.character() seemed to fix it! Thanks!

The next question I have is if areas are non-unique (e.g., because we have two months of data), what is the best way to tag the “date_range_start” or some other way to keep that indexed as well?

Oh cool!

As for date_range_start, you can just add that to the by option of expand_integer_json , i.e. by = c('area','date_range_start') and it will give you a separate row for each area for each date. You may want to convert date_range_start from a datetime to a date with as.Date() first since the hour information isn’t particularly informative.

Thank you!!