Created
April 16, 2018 19:40
-
-
Save mgahan/32ce2811832da8d3da767915a363ef31 to your computer and use it in GitHub Desktop.
This file contains hidden or 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(data.table) | |
check <- fread("https://storage.googleapis.com/playground-mike/weather/1315015.csv") | |
check[, .N, keyby=.(NAME)] | |
check <- check[, .(NAME, DATE,TMAX,TMIN)] | |
check <- na.omit(check, invert=FALSE) | |
check[, DATE := as.Date(DATE)] | |
check[, YEAR := year(DATE)] | |
check[, MONTH := month(DATE)] | |
# Check month count | |
check[, MonthCnt := .N, keyby=.(NAME, YEAR, MONTH)] | |
check <- check[MonthCnt > 25 & YEAR > 2011 & YEAR < 2018] | |
dcast(check[, .(Below32=sum(TMIN <= 32)), keyby=.(NAME, MONTH, YEAR)], YEAR+MONTH~NAME) | |
dcast(check[, .(Below32=sum(TMAX >= 95)), keyby=.(NAME, MONTH, YEAR)], YEAR+MONTH~NAME) | |
HighCompare <- dcast(check[, .(TMAX), keyby=.(NAME,DATE)], DATE~NAME) | |
HighCompare[month(DATE) %in% c(6,7,8), lapply(.SD, mean), .SDcols=-c("DATE")] | |
HighCompare[month(DATE) %in% c(12,1,2), lapply(.SD, mean), .SDcols=-c("DATE")] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment