Skip to content

Instantly share code, notes, and snippets.

View tengpeng's full-sized avatar

Teng Peng tengpeng

View GitHub Profile
DECLARE @cols AS NVARCHAR(MAX)=''
DECLARE @query AS NVARCHAR(MAX)=''
SELECT @cols = @cols + QUOTENAME(Crop) + ',' FROM (select distinct [Crop] from [FAF40].[dbo].[county_farm_acres2014] ) as tmp
set @query =
'SELECT * from
(
select StateCode, CountyCode, Crop from [FAF40].[dbo].[county_farm_acres2014]
) src
@tengpeng
tengpeng / k-fold CV.r
Last active November 20, 2016 15:56 — forked from bhoung/k-fold CV.r
# original example from Digg Data website (Takashi J. OZAKI, Ph. D.)
# http://diggdata.in/post/58333540883/k-fold-cross-validation-in-r
library(plyr)
library(randomForest)
data <- iris
# in this cross validation example, we use the iris data set to
cast([FINAL Freight Cost] as float)
cast(ISNULL([FINAL Freight Cost],0) as float)
NULLIF(CAST(ISNULL([FINAL Freight Cost],0) as float), 0)
convert(float,replace([FINAL Freight Cost],',','') )[FINAL Freight Cost]
CAST([FINAL Freight Cost] AS FLOAT) AS CastedValue
select * from GPC_INBOUND
where isnumeric([FINAL Freight Cost]) <> 1
To enable rJava support, run the following command:
R CMD javareconf JAVA_CPPFLAGS=-I/System/Library/Frameworks/JavaVM.framework/Headers
If you've installed a version of Java other than the default, you might need to instead use:
R CMD javareconf JAVA_CPPFLAGS="-I/System/Library/Frameworks/JavaVM.framework/Headers -I/Library/Java/JavaVirtualMachines/jdk<version>.jdk/"
(where <version> can be found by running `java -version`, `/usr/libexec/java_home`, or `locate jni.h`), or:
R CMD javareconf JAVA_CPPFLAGS="-I/System/Library/Frameworks/JavaVM.framework/Headers -I$(/usr/libexec/java_home | grep -o '.*jdk')"
@tengpeng
tengpeng / Setup New Mac by Brew and Cask
Last active October 31, 2016 15:40
Setup New Mac by Brew and Cask
sudo passwd pt
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew doctor
brew tap caskroom/cask
#brew install wget
brew install htop
#brew install zsh
#brew install aria2
@tengpeng
tengpeng / gist:63b222be183b64ffff5ed7fc1d05c5ab
Created October 29, 2016 00:45
Access date and time components in R
as.POSIXlt(as.Date(i))
orders$day <- orders$dd_mmm_yy$mday # day of month
orders$month <- orders$dd_mmm_yy$mon+1 # month of year (zero-indexed)
orders$year <- orders$dd_mmm_yy$year+1900 # years since 1900
# http://stackoverflow.com/questions/8126537/extract-date-elements-from-posixlt-and-put-into-data-frame-in-r
@tengpeng
tengpeng / gist:eabf0135e4e4a517a925cb27fbe00870
Last active October 28, 2016 04:03
Combine two ggplots into one
# Original two
ggplot(US_Propane_Weekly, aes(as.Date(date), value)) + geom_line() + xlab("date") + ggtitle("US_Propane_Weekly")
ggplot(Iowa_Propane_Monthly, aes(as.Date(date), value)) + geom_line() + xlab("date") + ggtitle("Iowa_Propane_Monthly")
# Combine into one
p = ggplot(US_Propane_Weekly, aes(as.Date(date), value)) + geom_line() + xlab("date") + ggtitle("US_Propane_Weekly vs. Iowa_Propane_Monthly")
p = p + geom_line(data = Iowa, aes(as.Date(date), value), colour="red")
p
@tengpeng
tengpeng / preprocessing.py
Created October 28, 2016 03:52
Skip header of Excel file
# coding: utf-8
# In[1]:
import openpyxl
import csv
# In[2]:
@tengpeng
tengpeng / lookup_var_name.py
Created October 27, 2016 05:51
This gist looks up variables' name by openpyxl in xlsx
# coding: utf-8
# In[1]:
import openpyxl
# In[2]: