Hello everybody!
Today I write about a short but pretty interesting topic. It is about analyzing which devices the Twitter users use and show them in a pie chart.
First of all, like always, we have to go through the authentification process I described here.
But then the fun can begin.
Getting the data
We start with searching on Twitter for Tweets containing a certain keyword. For my example I used “Social Media”.
1 |
tweets = searchTwitter("Social Media", n=20, cainfo="cacert.pem") |
Analyze Twitter Devices with R
We now have our tweets and just have to get the information about the source out of them. It is like searching for a string.
devices <- sapply(tweets, function(x) x$getStatusSource())
1 2 3 4 5 6 7 8 |
devices <- gsub("","", devices) devices <- strsplit(devices, ">") devices <- sapply(devices,function(x) ifelse(length(x) > 1, x[2], x[1]))[/code] Ok now we have our devices can put them in a nice looking pie chart like this one. [code language="r"] pie(table(sources)) |
Sometimes you can see interesting trends in the use of devices or maybe with a lot of luck you can find a new and unknown device.
Have fun!