Skip to content

Instantly share code, notes, and snippets.

View tengpeng's full-sized avatar

Teng Peng tengpeng

View GitHub Profile
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
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 / gist:63b222be183b64ffff5ed7fc1d05c5ab
Created October 29, 2016 00:45
Access date and time components in R
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
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")
tengpeng /
Created October 28, 2016 03:52
Skip header of Excel file
# coding: utf-8
# In[1]:
import openpyxl
import csv
# In[2]:
tengpeng /
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]:
reshape(dat1, idvar = "name", timevar = "numbers", direction = "wide")
tengpeng / a.rb
Created April 13, 2016 19:03
igonre warning
import warnings; warnings.filterwarnings("ignore");