Skip to content

Instantly share code, notes, and snippets.

View toyeiei's full-sized avatar
🎯
Focusing

Kasidis Satangmongkol toyeiei

🎯
Focusing
View GitHub Profile
@toyeiei
toyeiei / clean_na_with_R.r
Last active July 30, 2018 06:23
Clean missing values (NA) in R in these easy steps
# install tidyverse
install.packages("tidyverse")
library(tidyverse)
# step 1 -- review example dataset 'msleep' in tidyverse package
glimpse(msleep)
summary(msleep)
# step 2.1 -- remove all rows with missing values
clean_msleep <- drop_na(msleep)
@toyeiei
toyeiei / intro_to_sql.sql
Last active July 31, 2018 08:05
Introduction to SQL for everyone part I
-- SELECT clause to select specific columns
-- Select all columns from customers table
SELECT * FROM customers;
-- Select firstname, lastname and address columns from customers table
SELECT firstname, lastname, address FROM customers;
-- Use AS (alias) to change the column name
SELECT
firstname AS customer_firstname,
@toyeiei
toyeiei / .R
Last active November 2, 2018 10:56
data wrangling mini course - intro
# install package in R
install.packages("dplyr")
library(dplyr)
# useful functions to analyze dataframe
# review dataframe structure
glimpse(mtcars)
# print first six and last six rows
head(mtcars)
@toyeiei
toyeiei / .R
Created November 2, 2018 10:59
data wrangling mini course - dplyr
# dplyr five verbs
# select columns mpg, hp, wt, cyl from mtcars dataframe
select(mtcars, mpg, hp, wt, cyl)
# select column 1 to 5, 8 and 9
select(1:5, 8, 9)
# remove column 9 and 10
select(-9, -10)
@toyeiei
toyeiei / .sql
Created November 7, 2018 11:13
SQL for Beginner - SELECT
-- select all columns from table customers
SELECT * FROM customers;
-- select column firstname, lastname, email, phone from customers
SELECT
firstname,
lastname,
email,
phone
FROM customers;
@toyeiei
toyeiei / .sql
Last active November 8, 2018 02:24
SQL for Beginner - BASIC JOIN
-- JOIN two tables: album and artist
SELECT *
FROM artists
JOIN albums
ON artists.artistid = albums.artistid;
@toyeiei
toyeiei / .sql
Created November 8, 2018 02:24
SQL for Beginner - JOIN more than two tables
-- JOIN more than two tables
SELECT
artists.name,
albums.title,
tracks.name
FROM artists
JOIN albums
ON artists.artistid = albums.artistid
JOIN tracks
ON tracks.albumid = albums.albumid
@toyeiei
toyeiei / .sql
Last active November 8, 2018 04:09
SQL for Beginner - WHERE
-- where clause used to filter rows
-- filter only customers from USA
SELECT *
FROM customers
WHERE country = 'USA';
@toyeiei
toyeiei / .sql
Last active November 8, 2018 04:11
SQL for Beginner - AND OR
-- filter customers from USA who also live in CA state
SELECT *
FROM customers
WHERE country = 'USA' AND state = 'CA';
-- filter customers from USA or Brazil
SELECT *
FROM customers
WHERE country = 'USA' OR country = 'Brazil';
@toyeiei
toyeiei / .sql
Created November 9, 2018 01:07
SQL for Beginner - COUNT ROWS
-- count number of rows in table customers
SELECT COUNT(*)
FROM customers;