Commit 874d1a19 authored by O'Reilly Media, Inc.'s avatar O'Reilly Media, Inc.
Browse files

Initial commit

parents
Loading
Loading
Loading
Loading

README.md

0 → 100644
+15 −0
Changes for README.md: 15 added lines, 0 removed lines.
Original line number Diff line number Diff line
## Example files for the title:  
  
# Understanding SQL and R, by Casimir Saternos
  
[![Understanding SQL and R, by Casimir Saternos](http://akamaicovers.oreilly.com/images/9781491970287/cat.gif)](https://www.safaribooksonline.com/library/view/title/9781491970294//)
  
The following applies to example files from material published by O’Reilly Media, Inc. Content from other publishers may include different rules of usage. Please refer to any additional usage rights explained in the actual example files or refer to the publisher’s website.
  
O'Reilly books are here to help you get your job done. In general, you may use the code in O'Reilly books in your programs and documentation. You do not need to contact us for permission unless you're reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from our books does not require permission. Answering a question by citing our books and quoting example code does not require permission. On the other hand, selling or distributing a CD-ROM of examples from O'Reilly books does require permission. Incorporating a significant amount of example code from our books into your product's documentation does require permission.
  
We appreciate, but do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN.
  
If you think your use of code examples falls outside fair use or the permission given here, feel free to contact us at <permissions@oreilly.com>.
  
Please note that the examples are not production code and have not been carefully testing. They are provided "as-is" and come with no warranty of any kind.
+93 −0
Changes for Understanding SQL and R - Working Files/Chapter 1/create_outline.sh: 93 added lines, 0 removed lines.
Original line number Diff line number Diff line
#!/bin/bash 
# Description:
# -----------
# This is script to create a directory structure matching the 
# course outline (Learning SQL with R: Tools for Data Science).
#
# Author: Casimir Saternos
#
cd Chapter\ 1
touch Chapter_1_Introduction.txt
mkdir 0101_Welcome_to_the_Course
mkdir 0102_About_the_Author
mkdir 0103_Course_Overview
mkdir 0104_Current_Context
mkdir 0105_Introduction_to_SQL
mkdir 0106_Introduction_to_R
mkdir 0107_Software_Installation
mkdir 0108_RStudio_Overview
mkdir 0109_R_Packages
mkdir 0110_The_Relationship_between_R_and_SQL
mkdir 0111_Demo_Application_and_Database_Schema_Overview
cd ..

cd Chapter\ 2
touch Chapter_2_SQL_with_Single_Table_Results_Sets.txt
mkdir 0201_Relational_Theory_Review
mkdir 0202_Results_Sets
mkdir 0203_Processing_Results_Sets_with_R
mkdir 0204_Filtering_and_Ordering_with_SQL
mkdir 0205_Grouping_and_Summarizing_SQL
mkdir 0206_Modify_Results_using_SQL_Functions
cd ..

cd Chapter\ 3
touch Chapter_3_SQL_with_Multiple_Tables.txt
mkdir 0301_Common_Database_JOINs
mkdir 0302_Less-common_JOINs
mkdir 0303_Subqueries
mkdir 0304_Set_Operations
mkdir 0305_DBA_Considerations
mkdir 0306_Table-like_objects
mkdir 0307_Indexes
cd ..

cd Chapter\ 4
touch Chapter_4_R_Packages_and_SQL-like_Results_Set_Processing.txt
mkdir 0401_SQL_Results_Set_and_Tidy_Data
mkdir 0402_Processing_Results_Sets_with_R_vs_SQL
mkdir 0403_Filtering_and_Ordering_with_dplyr_vs._SQL
mkdir 0404_Grouping_and_Summarizing_with_dplyr_vs._SQL
mkdir 0405_Modify_Results_using_dplyr_and_R_Functions
mkdir 0406_Joins_using_dplyr
mkdir 0407_Set_operations_using_dplyr
mkdir 0408_Reshape_package
mkdir 0409_RTidy_Package
cd ..

cd Chapter\ 5
touch Chapter_5_Data_Artifacts_using_SQL_and_R.txt
mkdir 0501_Plotting_Database_Results_with_R
mkdir 0502_Plots_using_Base_R_Plots
mkdir 0503_Plots_using_Lattice
mkdir 0504_Plots_using_ggplot2
mkdir 0505_Plotting_Time_Series_Data
mkdir 0506_Creating_Maps_with_R
mkdir 0507_Creating_Reports_with_R
mkdir 0508_Web_Applications_with_R
cd ..

cd Chapter\ 6
touch Chapter_6_Data_Sources_and_Connections.txt
mkdir 0601_Sample_Data_Sets
mkdir 0602_Database_File_Exports_and_Imports
mkdir 0603_Local_Relational_Databases_rsqlite
mkdir 0604_Non-relational_data_sources
mkdir 0605_Remote_Connections
mkdir 0606_Troubleshooting_remote_connections
mkdir 0607_RJDBC
cd ..

cd Chapter\ 7
touch Chapter_7_Additional_Topics.txt
mkdir 0701_Derived_Tables
mkdir 0702_Vendor_Specific_SQL
mkdir 0703_Non-SQL_inspired_and_SQL-like_languages
mkdir 0704_R_inside_the_Database
mkdir 0705_Schema_Design_Considerations
cd ..

cd Chapter\ 8
touch Chapter_8_Conclusion.txt
mkdir 0801_Wrap_Up_and_Thank_You
cd ..
+47 −0
Changes for Understanding SQL and R - Working Files/Chapter 1/people.R: 47 added lines, 0 removed lines.
Original line number Diff line number Diff line
# R as a calculator
2 + 4

# Read the file as a data frame
people <- read.csv("~/Desktop/oreilly/sql_and_r_course/Chapter 1/resources/people.txt", stringsAsFactors=FALSE)
View(people)
class(people)

# View() and class() above are examples of functions.  There are functions
# that perform all kinds of operations.  Here are some examples of string 
# functions:

nchar('Joe')
paste0('this','that')

# R has built in plotting capabilities
hist(nchar(people$first_name))

# Additional capabilities are available through R packages.  The ggplot2
# package provides even more graphical capabilities.
library(ggplot2)

# The equivalent histogram to the one created above using base R can be
# created with this call.
ggplot(people, aes(x=nchar(first_name))) + geom_histogram(binwidth = 1)

# Note R's interactivity.  
# Just an up - arrow will give you the previous line of history...
# so the previous line can be modified.  This is great for interactive
# data exploration or building up plots.
ggplot(people, aes(x=nchar(last_name))) + geom_histogram(binwidth = 1)

ggplot(people, aes(x=nchar(last_name), y=nchar(first_name))) + geom_point()
ggplot(people, aes(x=nchar(last_name), y=nchar(first_name))) + geom_point() + geom_jitter()
ggplot(people, aes(x=nchar(last_name), y=nchar(first_name))) + geom_point() + geom_density2d()

# As strings of function calls become longer, it is necessary to organize
# the code differently.  One option is to break up calls on to multiple lines.
ggplot(people, 
       aes(x=nchar(last_name), y=nchar(first_name), 
                   label= paste0(nchar(first_name),
                                ',',
                                nchar(last_name)
                                )
           )
       ) + geom_text(alpha=0.3, color='blue') + geom_density2d()
+105 −0
Changes for Understanding SQL and R - Working Files/Chapter 1/people.txt: 105 added lines, 0 removed lines.
Original line number Diff line number Diff line
first_name,last_name,address
Alice,Atkins,123 Apple St.
John,Smith,234 Jefferson Rd.
Bob,Baker,5678 Benton Ln.
Aglae,Dibbert,6371 Jones Spurs
Alexander,Purdy,284 Reilly Squares
Alexandre,Wolf,338 Shanon Run
Allie,Hahn,77077 Kreiger Centers
Allison,Olson,6608 Torp Skyway
Andreanne,Weber,8171 Bernadine Greens
Andrew,Wunsch,18219 Carroll Unions
Annie,Friesen,35956 Corkery Village
Ara,Borer,80843 Kunze Island
Ardella,Howell,797 Keegan Valleys
Ashlee,Doyle,58352 Nichole Expressway
Ashton,Emard,412 Fahey Highway
Berneice,Donnelly,93700 Fisher Harbor
Bessie,Brekke,29246 Mueller Corners
Bettie,Tromp,909 Daugherty Walk
Birdie,Upton,98138 Devonte Coves
Boyd,Stanton,91516 Murphy Place
Buford,Wyman,190 Cortez Stravenue
Caleb,Lehner,217 Barrett Station
Christ,Rolfson,348 Rickie Vista
Clarissa,Braun,7588 Krajcik Port
Colby,Boyle,434 Fadel Land
Cynthia,Rippin,8364 Elda Ridge
Damon,Stanton,5842 Rosenbaum Trail
Dangelo,O'Kon,85714 Ritchie Highway
Danika,West,27511 Tracy Crest
Daron,Williamson,47932 Nigel Inlet
Davonte,Wehner,846 Katelin Crescent
Deanna,Kulas,57032 Abdiel Knolls
Desiree,Marvin,844 Welch Extension
Dolores,Kilback,315 Enoch Point
Domenick,Kuhic,7964 Willy Landing
Edwina,Legros,5400 Sven Fort
Eleazar,Greenholt,39212 King Ridge
Ellsworth,Walsh,7790 Johnny Lights
Eloy,Roob,6704 Jan Crescent
Elvie,Moore,9888 Torp Groves
Ernesto,Dooley,6320 Joaquin Road
Ezra,Goldner,539 Maryam Centers
Fanny,Adams,184 Beier Ports
Freddy,Larson,702 Celine Mews
Freeda,Klein,2363 Maiya Cliff
Freeman,Gislason,28624 Jerald Tunnel
Geraldine,Corwin,13410 Jo Fields
Gino,Zulauf,677 Elvera Parkway
Glen,Greenfelder,55416 Howell Ferry
Gracie,Cremin,1582 Howe Isle
Haley,Langworth,185 Cremin Court
Hellen,Aufderhar,19650 Goyette Trace
Hillary,Bergstrom,2785 Koss Meadow
Hillary,Legros,845 Gillian Lodge
Imelda,Hintz,814 Rosalyn Skyway
Jakayla,Stehr,9568 Sidney Neck
Janelle,Koepp,8251 Bechtelar Plaza
Jermey,Macejkovic,24802 Annetta Way
Josie,Hane,51555 Pascale Stravenue
Judson,Reichel,94797 Wolff Light
Julius,O'Conner,63304 Sarina Stream
Kane,Flatley,946 Yundt Crossing
Karley,Brakus,7093 O'Conner Groves
Kayleigh,Casper,8898 Kilback Pine
Kennedi,Wintheiser,3907 Mohr Fork
Kiel,Feest,6370 Hermina Square
Lane,Windler,9685 Gregorio Ports
Leda,Gusikowski,287 Candelario Centers
Leone,McCullough,239 Flatley Light
Leonel,Buckridge,202 Brakus Stream
Lillie,Stiedemann,258 Toy Orchard
Mackenzie,McCullough,5338 Jaron Curve
Mandy,Kilback,6672 Dicki Ridges
Marcelo,Green,5151 Thiel Views
Marvin,Ziemann,413 Douglas Spring
Maudie,Torp,6856 Rowland Branch
Maye,Schultz,2132 Jacobi Locks
Meggie,Erdman,253 Alessandro Lodge
Naomi,Bogisich,537 Johnnie Port
Nathanael,Von,1226 Florencio Lane
Noemi,Bosco,491 Corwin Falls
Ole,Reichert,68190 Letitia Greens
Oral,Willms,49630 Sarina Walks
Orrin,Stokes,627 Quigley Roads
Oswaldo,Donnelly,804 Spencer Crossroad
Reymundo,Bruen,236 Leffler Port
Rita,Reilly,135 Katrine Prairie
Rosalia,Leannon,8376 Wunsch Isle
Sadie,Volkman,5636 Alexandre Corners
Samir,Hilll,9189 Kiel Green
Sammie,Bins,2667 Llewellyn Flat
Sebastian,Schaefer,653 Bogan Mountain
Serenity,Lind,8451 Cara Station
Stevie,Rice,87686 Enoch Mountains
Sylvester,Hessel,396 Harber Trace
Tanya,Wuckert,728 Timmy Trafficway
Tiana,Pagac,99416 Champlin Viaduct
Tillman,Christiansen,3923 Lowe Crest
Timmy,Block,4230 Spencer Via
Verona,Ondricka,15131 Kaylee Trafficway
Webster,Schamberger,8168 Florian Terrace
Wilbert,Maggio,874 Nicolette Drives
Woodrow,Larson,267 Lew Islands
Zoe,Zetzger,999 Zebra Ave.
 No newline at end of file
+30 −0
Changes for Understanding SQL and R - Working Files/Chapter 1/sql_in_r.R: 30 added lines, 0 removed lines.
Original line number Diff line number Diff line
# Strings are enclosed in either single or double quotes:
string1 <- "Behold, a string"
string2 <- 'If possible, use "double quotes" in single quoted strings...'
string3 <- "...and 'single quotes' in double quoted strings"

# To include a quote of the same kind use \ to escape the character:

string4 <- "A \"double quote\" inside of a double quote."
string5 <- 'A \'single quote\' inside of a single quote.'

print(string4)

# print will display the backslash character used to escape.
# If you want to avoid this when displaying a string in the
# console, message or cat
message(string5)  


# Cat is short for concatenate, and is used to display 
# one or more strings.
cat(string4,string5)

# This is for display only.  
long_string <- cat(string4,string5)

# Use paste for variable assignment...
long_string <- paste(string4,string5)

# and paste0 if you don't want a space added between each string
cat(paste0(string4,string5))
Loading