This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_contracts = {} | |
class Contract: | |
@classmethod | |
def __init_subclass__(cls): | |
_contracts[cls.__name__] = cls | |
def __set__(self, instance, value): | |
self.check(value) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#@ 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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--#@@ [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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
OlderNewer