DATA MANAGEMENT MODULE: USING SQL in R

Slides:



Advertisements
Similar presentations
Haas MFE SAS Workshop Lecture 3:
Advertisements

Basic SQL Introduction Presented by: Madhuri Bhogadi.
A Guide to SQL, Seventh Edition. Objectives Create a new table from an existing table Change data using the UPDATE command Add new data using the INSERT.
Introduction to Structured Query Language (SQL)
A Guide to MySQL 7. 2 Objectives Understand, define, and drop views Recognize the benefits of using views Use a view to update data Grant and revoke users’
Introduction to SQL Session 1 Retrieving Data From a Single Table.
Introduction to Structured Query Language (SQL)
A Guide to SQL, Seventh Edition. Objectives Understand, create, and drop views Recognize the benefits of using views Grant and revoke user’s database.
Microsoft Access 2010 Chapter 7 Using SQL.
SAS SQL SAS Seminar Series
ASP.NET Programming with C# and SQL Server First Edition
PHP Programming with MySQL Slide 8-1 CHAPTER 8 Working with Databases and MySQL.
MS Access Database Connection. Database? A database is a program that stores data and records in a structured and queryable format. The tools that are.
Introduction to SQL Steve Perry
Computer Science 101 Database Concepts. Database Collection of related data Models real world “universe” Reflects changes Specific purposes and audience.
CPS120: Introduction to Computer Science Lecture 19 Introduction to SQL.
Using Special Operators (LIKE and IN)
BY SATHISH SQL Basic. Introduction The language Structured English Query Language (SEQUEL) was developed by IBM Corporation, Inc., to use Codd's model.
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
Introduction to Enterprise Guide Jennifer Schmidt Rhonda Ellis Cassandra Hall.
BACS 287 Structured Query Language 1. BACS 287 Visual Basic Table Access Visual Basic provides 2 mechanisms to access data in tables: – Record-at-a-time.
1 DBS201: Introduction to Structure Query Language (SQL) Lecture 1.
SQL Fundamentals  SQL: Structured Query Language is a simple and powerful language used to create, access, and manipulate data and structure in the database.
Access The L Line The Express Line to Learning 2007 L Line L © Wiley Publishing All Rights Reserved.
Introduction to Oracle In June 1970,Dr E.F.Codd’s a published A paper entitled A relational model of Data for large shared data banks. This relational.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
THE WEBMASTERS: SENG + WAVERING.  On account of construction, we will be having class in room 1248 next week.
Database UpdatestMyn1 Database Updates SQL is a complete data manipulation language that can be used for modifying the data in the database as well as.
NSF DUE ; Wen M. Andrews J. Sargeant Reynolds Community College Richmond, Virginia.
A Guide to SQL, Eighth Edition Chapter Six Updating Data.
A Guide to SQL, Eighth Edition Chapter Four Single-Table Queries.
SQL. Originally developed by IBM Standardized in 80’s by ANSI and ISO Language to access relational database and English-like non-procedural Predominant.
R Workshop #2 Basic Data Analysis. What we did last week: Understand the basics of how R works Generated objects (vectors, matrices, etc.) Read in data.
A Guide to MySQL 6. 2 Objectives Create a new table from an existing table Change data using the UPDATE command Add new data using the INSERT command.
7 1 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel 7.6 Advanced Select Queries SQL provides useful functions that.
LM 5 Introduction to SQL MISM 4135 Instructor: Dr. Lei Li.
Using Structured Query Language (SQL) NCCS Applications –MS Access queries (“show SQL”) –SAS (PROC SQL) –MySQL (the new dataserver) –Visual Foxpro Other.
Concepts of Database Management, Fifth Edition Chapter 3: The Relational Model 2: SQL.
Notes on SQL. SQL Programming Employers increasingly tell us that they look for 3 things on a resume: SAS, R and SQL. In these notes you will learn: 1.What.
Understanding Core Database Concepts Lesson 1. Objectives.
More SQL: Complex Queries, Triggers, Views, and Schema Modification
Session 1 Retrieving Data From a Single Table
Chapter 10: Accessing Relational Databases (Self-Study)
Oracle & SQL Introduction
DATA MANAGEMENT MODULE: Getting Data Into and Out of R
DATA MANAGEMENT MODULE: Subsetting and Formatting
DATA MANAGEMENT MODULE: Concatenating, Stacking and Merging
Data Management Module: Concatenating, Stacking, Merging and Recoding
An Introduction to SQL.
Tutorial 8 Objectives Continue presenting methods to import data into Access, export data from Access, link applications with data stored in Access, and.
DATA MANAGEMENT MODULE: Getting Data Into and Out of R
MS Access Database Connection
SQL FUNDAMENTALS CDSE Days 2018.
DATA MANAGEMENT MODULE: USING SQL in R
Chapter 8 Working with Databases and MySQL
DATA MANAGEMENT MODULE: Managing Variables
Lecture Set 14 B new Introduction to Databases - Database Processing: The Connected Model (Using DataReaders)
HMI 7530– Programming in R Introduction
STAT 4030 – Programming in R Introduction
DATA MANAGEMENT MODULE: Subsetting and Formatting
DATA MANAGEMENT MODULE: Concatenating, Stacking and Merging
DATA MANAGEMENT MODULE: Managing Variables
مقدمة في قواعد البيانات
A Guide to SQL, Eighth Edition
HAVING,INDEX,COMMIT & ROLLBACK
Data Management Module: Subset, Sort, and Format data
Structured Query Language – The Fundamentals
CSCI N317 Computation for Scientific Applications Unit R
Data Management Module: Creating, Adding and Dropping Variables
Understanding Core Database Concepts
Presentation transcript:

DATA MANAGEMENT MODULE: USING SQL in R STAT 4030 – Programming in R DATA MANAGEMENT MODULE: USING SQL in R Jennifer Lewis Priestley, Ph.D. Kennesaw State University 1

DATA MANAGEMENT MODULE Importing and Exporting Imputting data directly into R Creating, Adding and Dropping Variables Assigning objects Subsetting and Formatting Working with SAS Files Merging, Stacking and Recoding Using SQL in R 2 2 2

Data Management Module: SQL Definition of SQL: The original Structured Query Language was designed by an IBM research center in 1974-75 and introduced commercially by Oracle in 1979. There are different dialects of SQL, but it remains as close to a standard query language as you will get. Some standard SQL commands are as follows: SELECT DELETE INSERT CREATE UPDATE DROP 3

Data Management Module: SQL SQL is used for the following tasks: Generate reports Generate summary statistics Retrieve data from tables or views Combine data from tables or views Create tables, views, and indexes Update the data values in SQL tables Update and retrieve data from database management system (DBMS) tables. 4

Data Management Module: SQL To get started using SQL in R, you first need to install the “sqldf” package. Basically sqldf is a function that tells R that you are now coding in SQL – much like calling PROC SQL in SAS. 5

Data Management Module: SQL SELECT – this SQL term will allow you to select all or a portion of rows/columns from a data frame sqldf('select * from PS2') The “*” is the symbol that represents all rows and columns sqldf('select Tattoo, Looks from PS2') Selecting individual columns (vectors) is simple – just separate the column names by a comma (no final comma). sqldf('select Sex, ((HtChoice-Height)/Height)*100 as PCTDIFF from PS2') You can create new variables at the same time that you select them. 6

Data Management Module: SQL WHERE – this SQL term will allow you to select only a specified set of observations. This is particularly useful if there are values that are either clearly illogical (like negative age) or statistically unlikely (like adult height less than 50”) sqldf('select * from PS2 where HtChoice >=60') sqldf('select Sex, Tattoo from PS2 where Sex="Male" AND Height >70’) 7

Data Management Module: SQL Summarization – you can do some basic summarization in the context of SQL programming that is very efficient. Some examples include: AVG, MEAN, COUNT, NMISS, RANGE, STD, SUM. sqldf('select Sex, count(Sex) N, avg(NumPrces) AVG_NumPrces, stdev(NumPrces) StdDev from PS2 group by Sex') Note that in this code, you will be generating the requested statistics only for the variable that you specify after the term. 8 8