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
!["This page in json format"](https://cdn-wordpress-info.futurelearn.com/info/wp-content/uploads/78e49929-94d5-45b2-8961-8c06e85c9ac6-768x505.png)
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
![](https://ugc.futurelearn.com/uploads/images/3f/2d/promo_small_3f2d021a-4c54-4f33-b524-188022ad610b.jpg)
Big Data: Measuring And Predicting Human Behaviour
![](https://ugc.futurelearn.com/uploads/images/3f/2d/promo_small_3f2d021a-4c54-4f33-b524-188022ad610b.jpg)
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