Skip to content

Instantly share code, notes, and snippets.

View gist:2ed76b50181bf30eab47c3fdcff038a3
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
View gist:55817cb29be834acfd2323dfcbe0ab95
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
View gist:c0ce7422bd5c6d887b5a4fca2f1f3d79
select * from GPC_INBOUND
where isnumeric([FINAL Freight Cost]) <> 1
View gist:4319863d16e296f8b8d2929a92019ddf
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 / gist:63b222be183b64ffff5ed7fc1d05c5ab
Created Oct 29, 2016
Access date and time components in R
View gist:63b222be183b64ffff5ed7fc1d05c5ab
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
View gist:eabf0135e4e4a517a925cb27fbe00870
# 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 Oct 28, 2016
Skip header of Excel file
View preprocessing.py
# coding: utf-8
# In[1]:
import openpyxl
import csv
# In[2]:
@tengpeng
tengpeng / lookup_var_name.py
Created Oct 27, 2016
This gist looks up variables' name by openpyxl in xlsx
View lookup_var_name.py
# coding: utf-8
# In[1]:
import openpyxl
# In[2]:
View gist:b1341ede0736c3a6657d3befdc4638e2
reshape(dat1, idvar = "name", timevar = "numbers", direction = "wide")
@tengpeng
tengpeng / a.rb
Created Apr 13, 2016
igonre warning
View a.rb
import warnings; warnings.filterwarnings("ignore");