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(rJava) | |
.jinit() | |
.jaddClassPath(dir( "/home/jal/Documents/DSSAT/gsrad/gsrad_sample/lib/", full.names=TRUE )) | |
attach( javaImport( c("java.lang", "java.io"))) | |
BristowCampbellStrategy <- function(b, ClearSkyTransmissivity, ExtraTerrestrialRadiation, SlopeAspectFactor, AirTemperatureDailyRange, AirTemperatureMonthlyRange ) { | |
rd <- .jnew( "cra/clima/gsrad/RadData" ) | |
algo <- .jnew( "cra/clima/gsrad/GSRBristowCampbellStrategy" ) | |
bcParams <- .jnew( "cra/clima/gsrad/BristowCampbellParameters" ) |
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
## make some non norm data | |
d1 <- rnorm(20, 5, 1) | |
d2 <- rnorm(5, 10, 2) | |
d <- c(d1,d2) | |
hist(d) | |
## no mean adjustment | |
myUniform <- ecdf( d )( d ) | |
mean( myUniform ) | |
## hey that mean's not .5! |
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
n <- 1e7 | |
myDf <- data.frame( a=rnorm(n), b=rnorm(n), c=rnorm(n) ) | |
myDf <- rbind(myDf, myDf) | |
# memory use doubles every time the rbind() runs. | |
# see what happens if you keep running the this over and over | |
# I have 4GB of RAM in my laptop running 64 bit Ubuntu. | |
# R gets killed after 2 rbind() | |
myDf <- rbind(myDf, myDf) |
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
estimatePi <- function(seed){ | |
set.seed(seed) | |
numDraws <- 1e6 | |
r <- .5 #radius... in case the unit circle is too boring | |
x <- runif(numDraws, min=-r, max=r) | |
y <- runif(numDraws, min=-r, max=r) | |
inCircle <- ifelse( (x^2 + y^2)^.5 < r , 1, 0) | |
return(sum(inCircle) / length(inCircle) * 4) | |
} |
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(rJava) | |
.jinit() | |
awsAccessKeyText <- "yourKeyHere" | |
awsSecretKeyText <- "yourSecretKeyHere" | |
pathToSdk <- "/home/jal/aws-java-sdk-1.1.0/" | |
testFile <- "/home/jal/aws-java-sdk-1.1.0/rJavaExamples/testFile.tst" | |
.jaddClassPath(paste(pathToSdk, "lib/aws-java-sdk-1.1.0.jar", sep="")) | |
.jaddClassPath(paste(pathToSdk, "third-party/commons-logging-1.1.1/commons-logging-1.1.1.jar", sep="")) |
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
# Thanks to @greghirson who totally knocked this out of the park! | |
# Based on his work, here's a simple script to pull monthly prices from the USDA NASS website. | |
library(RCurl) | |
library(XML) | |
x <- postForm(uri = "http://quickstats.nass.usda.gov/uuid/encode", | |
source_desc = "SURVEY", sector_desc="CROPS", | |
group_desc="FIELD CROPS", commodity_desc="CORN", | |
statisticcat_desc="PRICE RECEIVED", |
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
a | b | |
---|---|---|
1 | 2 | |
2 | 3 | |
3 | 4 | |
4 | 5 |
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
set.seed(2) | |
x <- 1:100 | |
y <- 20 + 3 * x | |
e <- rnorm(100, 0, 60) | |
y <- 20 + 3 * x + e | |
plot(x,y) | |
yx.lm <- lm(y ~ x) | |
lines(x, predict(yx.lm), col="red") |
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
# multivariate normal example using Cholesky decomposition | |
require(Matrix) | |
#make this reproducible | |
set.seed(2) | |
#how many draws in our starting data set? | |
n <- 1e4 |
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
# multivariate normal example using the MASS package | |
require(MASS) | |
#make this reproducible | |
set.seed(2) | |
#how many draws in our starting data set? | |
n <- 1e4 |