1 Peter Fox Data Analytics – ITWS-4963/ITWS-6965 Week 3b, February 7, 2014 Lab exercises: datasets and data infrastructure
Assignment 2 – graded in lab. General assignment – read EPI_data, specify a new data subset, create data frames in R and save them into a database In R Studio –Install package – “rmongodb” (activate it) – MongoDB - – couchdb-vs-redishttp://kkovacs.eu/cassandra-vs-mongodb-vs- couchdb-vs-redis 2
Install Start the MongoDB server (with privileges) Use the Mongo command line: mongo or mongodb > help > db > use local #(or test) At this point you could insert new items in the db but we’ll leave that for later > for (var i = 1; i <= 25; i++) db.local.insert( { x : i } ) > db.local.find() 3
Then switch to R or Rstudio Read EPI_data in (again!) Using the slide from the tab in the Excel spreadsheet (reminder in next slide) Create two data frames with: 1.The key indicators from EPI_data (and one independent variable) – I call this dfEPI 2.The weights assigned to each indicator in the EPI “model” and “sub-models” (you can choose the data structures) 4
The model and sub-models 5
Then switch to R or Rstudio Connect to the running DB (MacOS): > mongo = mongo.create(host=" ",db="local") > mongo.is.connected(mongo) > bEPI <- mongo.bson.from.list(as.list(dfEPI)) > mongo.insert(mongo,'dfEPI.EPI',bEPI) #same for the second data frame (weights) > mongo.get.databases(mongo) # similar cmds in mongo > mongo.get.database.collections(mongo,"dfEPI") > cdf=mongo.find.all(mongo,"dfEPI.EPI") > cdf > mongo.destroy(mongo) #when done only 6
Back to MongoDB $ mongodb# command line show dbs use show collections 7
For Assignment Show creation of data frames (in R) Export into MongoDB (in R) Verify that it is there (in mongo) Future – query/read it back, use it. 8
Admin info (keep/ print this slide) Class: ITWS-4963/ITWS 6965 Hours: 12:00pm-1:50pm Tuesday/ Friday Location: SAGE 3101 Instructor: Peter Fox Instructor contact: (do not leave a Contact hours: Monday** 3:00-4:00pm (or by appt) Contact location: Winslow 2120 (sometimes Lally 207A announced by ) TA: Lakshmi Chenicheri Web site: –Schedule, lectures, syllabus, reading, assignments, etc. 9