R에서 실행하는 SQL 쿼리

R 데이터 가져오기 중급

Filip Schouwenaars

Instructor, DataCamp

ch_2_1_slides.003.png

R 데이터 가져오기 중급

ch_2_1_slides.004.png

R 데이터 가져오기 중급

ch_2_1_slides.005.png

R 데이터 가져오기 중급

ch_2_1_slides.006.png

R 데이터 가져오기 중급

ch_2_1_slides.007.png

R 데이터 가져오기 중급

선택적 가져오기

  • SQL 쿼리

  • DBI -> RMySQL, RPostgreSQL, ...

  • SQL 기본만 다룹니다

R 데이터 가져오기 중급

company

ch_2_1_slides.012.png

R 데이터 가져오기 중급

company

ch_2_1_slides.013.png

R 데이터 가져오기 중급

패키지 로드 및 연결

library(DBI)con <- dbConnect(RMySQL::MySQL(),
         dbname = "company",
         host = "courses.csrrinzqubik.us-
                          east-1.rds.amazonaws.com",
         port = 3306,
         user = "student",
         password = "datacamp")
R 데이터 가져오기 중급

예제 1

employees <- dbReadTable(con, "employees")
subset(employees, 
         subset = started_at > "2012-09-01", 
         select = name)
     name
3   Julie
4 Heather
5    John
dbGetQuery(con, "SELECT name FROM employees 
                      WHERE started_at > '2012-09-01'")
     name
1   Julie
2 Heather
3    John
R 데이터 가져오기 중급

예제 1

ch_2_1_slides.027.png

R 데이터 가져오기 중급

예제 1

ch_2_1_slides.028.png

R 데이터 가져오기 중급

예제 1

ch_2_1_slides.029.png

R 데이터 가져오기 중급

예제 1

ch_2_1_slides.030.png

R 데이터 가져오기 중급

예제 1

ch_2_1_slides.031.png

R 데이터 가져오기 중급

예제 1

ch_2_1_slides.032.png

R 데이터 가져오기 중급

company

ch_2_1_slides.034.png

R 데이터 가져오기 중급

company

ch_2_1_slides.035.png

R 데이터 가져오기 중급

예제 2

products <- dbReadTable(con, "products")

subset(products, subset = contract == 1)
  id          name contract
2  2     Call Plus        1
4  9 Biz Unlimited        1
dbGetQuery(con, "SELECT * FROM products 
                                   WHERE contract = 1")
  id          name contract
1  2     Call Plus        1
2  9 Biz Unlimited        1
R 데이터 가져오기 중급

연습해 봅시다!

R 데이터 가져오기 중급

Preparing Video For Download...