Understanding Wikipedia Data Using R
Note: In order to see the details of the commands and screen-based information it is best to view this video full screen and in HD. However, if you’d like to have a go yourself, we strongly recommend you follow the instructions in the text below. Here, we tell you what the commands in the video are, and we also have made a couple of small updates to the text since we recorded this video which will help you get your code to work. You’ll find following the text a lot easier than copying the commands from the video.
Wikipedia’s Available Data
Understanding Wikipedia Data Using R
R and R Studio
cat("Hello, World...")
cat("Hello again, World!") # This is a comment
Command R
?install.packages
Understanding Wikipedia Data Using R
install.packages("RCurl")
library(RCurl)
getURL("http://stats.grok.se/json/en/201410/Friday")
rawData <- getURL("http://stats.grok.se/json/en/201410/Friday")
rawData
install.packages("RJSONIO") # Install the JSON parser
library(RJSONIO) # Load the JSON parser
Note: where the code consists of more than one line of code you must hit ‘Enter’ at the end of each line.
To parse the JSON, we can use a function called “fromJSON”:
fromJSON(rawData)
What comes out of this function looks a bit more understandable, particularly the bit under “$daily_views”. Let’s save the parsed data in a variable called “parsedData”:
parsedData <- fromJSON(rawData)
Let’s check what’s now saved in parsedData, by typing the variable name into the Console:
parsedData
… looks good.
How can we access the information in the variable labelled “$daily_views”? Try typing this in
parsedData$daily_views
OK – it looks like we’ve got something which is a bit more like a table!
Excellent – you’ve downloaded data on how often people are looking at a Wikipedia page and loaded it into R!
Big Data: Measuring And Predicting Human Behaviour
Big Data: Measuring And Predicting Human Behaviour
Reach your personal and professional goals
Unlock access to hundreds of expert online courses and degrees from top universities and educators to gain accredited qualifications and professional CV-building certificates.
Join over 18 million learners to launch, switch or build upon your career, all at your own pace, across a wide range of topic areas.
Register to receive updates
-
Create an account to receive our newsletter, course recommendations and promotions.
Register for free