Importing the file into RStudio's working environment
From an existing table in dashDB
1. Launch the dashDB service on BlueMix.
2. Go to Top-Left Menu > Analyze > Develop R Scripts.
3. Click on the "+" sign to the left of the "RStudio" button.
4. Find your table in the available schemas (usually under a DASH### schema).
5. Click on the table, choose the desired Columns and click Apply.
6. You will see some R script generated. For example:
7. library(ibmdbR)
8. mycon <- idaConnect("BLUDB", "", "")
9. idaInit(mycon)
10. df1416955470415 <-
[Link]([Link]('"DASH100555"."myfile"')[ ,c("Date","ID","Info")])
11. Click on Save and enter a name to save this script as a .R file. You will be able to access this file in RStudio.
12. Launch RStudio by clicking on the RStudio button in the left panel.
13. In the Files tab in the bottom right, you should be able to see the .R file you just made. Click to open it.
14. Before running the commands, you may want to change the name of your dataframe variable into something
shorter.
15. Run the commands in the script. Your dataframe will be loaded into your R Environment!
16. Congratulations! Now you can start exploring your data in RStudio.
From an existing file in RStudio.
1. Launch RStudio through dashDB (Top-Left Menu > Analyze > Develop R Scripts, then RStudio).
2. In the Files tab in the bottom-right window, verify that your file exists in one of the folders.
3. In the R script window, use the command:
4. [Link]("[Link]")
and you may want to assign it to a variable, such as df.
5. Congratulations! Now you can start exploring your data!
Lab 4: Uploading the full election results:
Data from [Link]
Load the full election results from election_results.csv
1. Download "election_results.csv" from [Link]
2. Note the local filepath of "election_results.csv".
3. Run:
4. results <- [Link]("YOURFILEPATH/election_results.csv")
5. Print the contents of results.
6. Use sum(vector) to calculate the sum of numbers in a vector.
o In total, how many people voted?
o What is the total number of votes for candidates excluding the top three candidates (John Tory,
Doug Ford, and Olivia Chow)? And as a percentage?
o Check if the total percentage of votes adds up to 100%. Why does it not?
7. getwd()
setwd("/Users/polong/Dropbox/Meetups/SMAC- Intro to R/")
[Link]()
results <- [Link]("election_results.csv")
Resources for learning R
Basics of R
• [R package] RSwirl
o a package in R to teach you R
o R basics up to linear regression
o [Link]
• [Online Course] R Programming on Coursera
o Video lectures and assignments on R programming
o [Link]
• [Online Course] Introduction to Data Analysis using R on Big Data University
o Created by Grant Hutchison
o Videos and Labs in R
o [Link]
Learning to do more in R
• [Online Courses] Data Science Specialization on Coursera
o A series of 9 courses on data science using R
o Github
o Data Cleaning
o Data visualization (base, ggplot2)
o R markdown, knitr
o Statistical inference
o Regression models (linear, Poisson, logistic)
o Machine learning (random forests, PCA)
o Interactive web applications with R running in the background (Shiny)
o [Link]
• [Online Tutorials] Kaggle Tutorials on Machine Learning
o [Link]
Statistics using R
• [Textbook] Discovering Statistics using R
o by Andy Field, Jeremy Miles, Zoë Field
o [Link]
Statistical (Machine) Learning in R
• [Videos and Textbook] An Introduction to Statistical Learning with Applications in R
o [Link]
Blogs on R
• [Link]
Troubleshooting
• Stack Overflow
o [Link]