Roy Roy - 15 days ago 5
R Question

Extract tweets and the users only from a particular location using R

I want to compare the brand knowledge (Ex : Sony) in Dublin and London. How will you select the tweets only from those locations with the user name who tweeted it? I tried for the London one with the geocode option, But it returned zero. This is my code:

tweets <- searchTwitter(
"@Sony", n = 1000, since = "2014-01-01",
lang = "en", geocode = "51.5074, 0.1278"
)


Is there a better way to do this?

Answer

You need to remove the spaces in the geocode parameter, and you also need to specify a distance representing a radius against the lat/long point you specify. For example, if you wanted a radius of 50km, you would use this:

tweets <- searchTwitter(
    "@Sony", n = 1000, since = "2014-01-01",
   lang = "en", geocode = "51.5074,0.1278,50km"
)

From the twitteR documentation:

geocode - If not NULL, returns tweets by users located within a given radius of the given latitude/longitude.

and

For the geocode argument, the values are given in the format latitude,longitude,radius, where the radius can have either mi (miles) or km (kilometers) as a unit. For example geocode='37.781157,-122.39720,1mi'.

Notice carefully that there are no spaces in the geocode parameter.

Comments