Skip to content

Instantly share code, notes, and snippets.

View mkim0710's full-sized avatar

mkim0710 mkim0710

View GitHub Profile
@mkim0710
mkim0710 / p1.r
Created March 22, 2017 23:17 — forked from Eunsol-Lee/p1.r
solve <- function(n) {
result <- largeSubtract(largeAdd(sumMultiple(n, 3), sumMultiple(n, 5)), sumMultiple(n, 15))
}
right <- function (string, char){
substr(string,nchar(string)-(char-1),nchar(string))
}
left <- function (string,char){
substr(string,1,char)
url_Data <- readLines("https://raw.githubusercontent.com/issactoast/Machine-Learning-with-R/master/Data/house.txt") %>% paste(collapse = "\n")
houseData <- read.table(text = url_Data, header = FALSE, sep = ":")
houseData
for (i in 1:dim(houseData)[2]){
houseData[,i] <- gsub(paste("",i), "", houseData[,i])
}
houseData <- houseData %>% unlist() %>% as.numeric() %>% matrix(ncol = 14)
colnames(houseData) <- c("MEDV", "CRIM", "ZN", "INDUS",
"CHAS", "NOX", "RM", "AGE",
"DIS", "RAD", "TAX", "PTRATIO",
@mkim0710
mkim0710 / contract.py
Created July 19, 2017 05:00 — forked from 20chan/contract.py
The Fun of Reinvention 최종
_contracts = {}
class Contract:
@classmethod
def __init_subclass__(cls):
_contracts[cls.__name__] = cls
def __set__(self, instance, value):
self.check(value)
@mkim0710
mkim0710 / microbenchmark-blog-post.R
Created July 28, 2017 19:56 — forked from stephenturner/microbenchmark-blog-post.R
Code for GGD blog post on microbenchmark
# see blog post here:
# http://gettinggeneticsdone.blogspot.com/2015/01/microbenchmark-package-r-compare-runtime-r-expressions.html
library(dplyr)
library(nycflights13)
flights
# base
aggregate(flights$arr_delay, by=list(flights$carrier), mean, na.rm=TRUE)
@mkim0710
mkim0710 / library(RODBC) Big Data Management 2018 HW1 Grading.r
Last active February 19, 2018 18:53
library(RODBC) Big Data Management 2018 HW1 Grading
function.list_TABLE_NAME.sqlFetch_sqlColumns = function(channel) {
# source("https://gist.githubusercontent.com/mkim0710/09f4626f80edd8c837b8834ef1685f31/raw/e825646ba318ce55d491ea7a61696c1ec8a2dd1f/library(RODBC)%2520Big%2520Data%2520Management%25202018%2520HW1%2520Grading.r")
library(RODBC)
library(tidyverse)
out = filter(sqlTables(channel), TABLE_TYPE == "TABLE")$TABLE_NAME %>% map(function(x) {
tmp.list = list()
tmp.list$sqlFetch = sqlQuery(channel, paste0("SELECT * FROM ", x))
tmp.list$sqlColumns = sqlColumns(channel, x)
tmp.list
})
library(tidyverse)
library(readxl)
Big_Data_Management_Student_List_2018 = read_excel("D:/tmp.files/[[Big Data Management]] Student List 2018.xlsx")[1:44, c("First Name", "Last Name", "CWID")]
vec.new.file.name = Big_Data_Management_Student_List_2018 %>% transmute(new.file.name = paste0(`Last Name`, ", ", `First Name`, " (", CWID, ")")) %>% unlist %>% unname
current.folder = "D:/[[Big Data Management]] 2018/HW1"
original.file.name = "HW1 Gradesheet 2018.xlsx"
new.folder = "D:/[[Big Data Management]] 2018/HW1 Gradesheet 2018"
for (i in 1:length(vec.new.file.name)){
file.copy(
overwrite = T
@mkim0710
mkim0710 / MWEblogpost.Rmd
Created May 19, 2018 16:07 — forked from jknowles/MWEblogpost.Rmd
R Markdown of blog post on R minimal working examples (MWE).
How to Ask for Help using R
========================================================
The key to getting good help with an R problem is to provide a minimally working
reproducible example (MWRE). Making an MWRE is really easy with R, and it will
help ensure that those helping you can identify the source of the error, and
ideally submit to you back the corrected code to fix the error instead of sending
you hunting for code that works. To have an MWRE you need the following items:
- a minimal dataset that produces the error
#@ function.11matching.by.factors() -----
function.11matching.by.factors = function(data, varname4MatchingUpon = "diabetes", varnames4MatchingBy = c("age", "sex"), seed = 1) {
library(tidyverse)
if ("RowNum_original" %in% names(data)) {
warning('"RowNum_original" %in% names(data)')
} else {
data$RowNum_original = 1:nrow(data)
}
set.seed(seed)
data$runif = runif(nrow(data))
--#@@ [Research] HCCI MDD annual prevalence 180501.pptm -p128.sql ----
select count(z_patid), count(distinct z_patid)
from hcci.MEMBER_SDDV2_1115
where (
z_patid in (
select z_patid
from hcci.MEMBER_SDDV2_1115
where (
gdr in ('1', '2')
@mkim0710
mkim0710 / ID_207_Group_Project_Version_2_Vertical_July_24_2018_07_34.rowMeans.na.omit from .r
Created July 28, 2018 20:32
ID_207_Group_Project_Version_2_Vertical_July_24_2018_07_34.rowMeans.na.omit from .r
ID_207_Group_Project_Version_2_Vertical_July_24_2018_07_34 %>% mutate(
Q3138rowMeans = rowMeans(.[, c("Q31", "Q32", "Q33", "Q34", "Q35", "Q36", "Q37", "Q38")], na.rm = T)
, Q3138rowSums = rowSums(.[, c("Q31", "Q32", "Q33", "Q34", "Q35", "Q36", "Q37", "Q38")], na.rm = T)
, Q4044rowMeans = rowMeans(.[, c("Q40", "Q41", "Q42", "Q43", "Q44")], na.rm = T)
, Q4044rowSums = rowSums(.[, c("Q40", "Q41", "Q42", "Q43", "Q44")], na.rm = T)
) %>% select(Q31, Q32, Q33, Q34, Q35, Q36, Q37, Q38, matches("Q3138"), Q40, Q41, Q42, Q43, Q44, matches("Q4044")) %>%
# > ID_207_Group_Project_Version_2_Vertical_July_24_2018_07_34 %>% mutate(
# + Q3138rowMeans = rowMeans(.[, c("Q31", "Q32", "Q33", "Q34", "Q35", "Q36", "Q37", "Q38")], na.rm = T)
# + , Q3138rowSums = rowSums(.[, c("Q31", "Q32", "Q33", "Q34", "Q35", "Q36", "Q37", "Q38")], na.rm = T)