Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to extract tweet geocode in twitteR package in R

Tags:

r

twitter

geocode

Recently Edwin Chen posted a great map of the regional usage of soda vs pop vs coke created from geocoded tweets inolving those words in the context of drinking. http://blog.echen.me/2012/07/06/soda-vs-pop-with-twitter/

He mentions that he used the twitteR package created by Jeff Gentry in R. Sure enough, it is easy to gather tweets that use a given word and put them in a dataframe:

require(twitteR)
require(plyr)
cat.tweets<-searchTwitter("cats",n=1000)
tweets.df = ldply(cat.tweets, function(t) t$toDataFrame() ) 

the dataframe (tweets.df) will contain the user id, tweet text, etc. for each tweet, but does not appear to contain the geocode. Any idea on how to get it in R?

like image 315
iantist Avatar asked Jul 26 '12 17:07

iantist


People also ask

How do I search Tweets by geocode?

To do a geographic search, Twitter offers two options: using the near: and within: prefixes or using the geocode: prefix. For the former, to find tweets from the Philadelphia area that mention the word “museum,” you can search for museum near:Philadelphia within:5mi .

How do I get geolocation on Twitter?

To sign up for geolocation on your Twitter account, click your username in the top right-hand corner of the page and select “Settings” from the drop-down menu. Click the check box beside “Add a Location to Your Tweets” to select and enable the feature.

Does Twitter have geo?

The has:geo operator matches for the presence of either Point or Place geo information within the Twitter payload. Note that this does not allow you to specify specific locations or types of geo data, it simply requires that results have Tweet-specific location information of some kind.


1 Answers

Does geocode mean longitude and latitude coordinate? If yes, following commands works for me.

cat.tweets = searchTwitter("cats",n=1000)
tweets.df = do.call("rbind",lapply(cat.tweets,as.data.frame))

Source : LINK

like image 122
nurandi Avatar answered Oct 15 '22 19:10

nurandi