Recipe 14 Performing Setwise Operations on Friendship Data
You want to operate on collections of friends and followers to answer questions such as “Who isn’t following me back?”, “Who are my mutual friends?”, and “What friends/followers do certain users have in common?”.
Use R setwise operations and
R has set operations and they’ll do just fine for helping us cook this recipe.
If you need a refresher on set operations, check out this introductory lesson from Khan Academy.
Now we can see the count of mutual and disparate relationships:
##  50
##  226
The Python counterpart to this cookbook suggests Redis as a “big-ish” data solution for performing set operations at-scale. R has at least 3 packages that provide direct support for Redis, so if you need to perform these operations at-scale, cache the info you retrieve from the Twitter API into Redis and then go crazy!
14.4 See Also
- Google (yes, seriously)
redis packages rto see the impressive/diverse number of packages linking R to Redis
- Official Twitter API documentation on friends and followers.