This file contains 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) | |
library(lattice) | |
## Create a toy example | |
dt <- data.table(A=rnorm(1e7, mean=0, sd=1)) | |
## Bin the data using equal-width intervals | |
brks <- seq(-6, 6, length=10000) | |
## and := to avoid an additional copy | |
dt[,bin:=findInterval(A, brks)] | |
## Finally aggregate with mean by bin |
This file contains 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) | |
data(movies, package='ggplot2') | |
library(lattice) | |
movies <- data.table(movies) | |
nBins <- 500 | |
## 2D Binning | |
movies[, c('ratBin', 'votesBin'):=list(floor(rating/nBins), floor(votes/nBins))] |
This file contains 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(sp) | |
library(ggmap) | |
library(RColorBrewer) | |
## Get data from OpenPV. Open this URL: | |
## https://openpv.nrel.gov/search?&state=CA&minsize=100&maxsize=30600&pagenum=1&nppage=25 | |
## and export the results as a CSV file named "californiaOpenPV.csv" | |
caPV <- read.csv('californiaOpenPV.csv') | |
## Longitude and Latitude are the names of columns where the spatial information is stored. | |
## With the coordinates<- method caPV is now an SpatialPointsDataFrame |
This file contains 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(raster) | |
library(rasterVis) | |
library(maptools) ## for readShapeLines | |
library(colorspace) ## for terrain_hcl | |
## Get data from GADM and DIVA-GIS | |
setwd(tempdir()) | |
download.file('http://www.gadm.org/data/shp/ETH_adm.zip', 'ETH_adm.zip') | |
unzip('ETH_adm.zip', exdir='.') | |
download.file('http://www.diva-gis.org/data/msk_alt/ETH_msk_alt.zip', 'ETH_msk_alt.zip') |
This file contains 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(solaR) | |
## Monthly averages of daily values (Wh/m2) | |
G0dm <- c(2.766,3.491,4.494,5.912,6.989,7.742,7.919,7.027,5.369,3.562,2.814,2.179)*1000; | |
Ta <- c(10, 14.1, 15.6, 17.2, 19.3, 21.2, 28.4, 29.9, 24.3, 18.2, 17.2, 15.2) | |
g0 <- calcG0(lat=37.2, modeRad='aguiar', dataRad=G0dm) | |
xyplot(g0) |
This file contains 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(solaR) | |
## Download data from NREL (see help(calcG0)) | |
NRELurl <- 'http://goo.gl/fFEBN' | |
dat <- read.table(NRELurl, header=TRUE, sep=',') | |
names(dat) <- c('date', 'hour', 'G0', 'B', 'D0', 'Ta') | |
##B is direct normal. We need direct horizontal. | |
dat$B0 <- dat$G0-dat$D0 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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(sp) | |
library(rgdal) | |
setwd(tempdir()) | |
download.file('https://raw.github.com/oscarperpinan/solar/gh-pages/data/SIAR.csv', 'siar.csv', method='wget') | |
siar <- read.csv('siar.csv') | |
summary(siar) | |
siarSP <- SpatialPointsDataFrame(siar[,c(6, 7)], siar[,-c(6,7)]) | |
writeOGR(siarSP, 'siar.geojson', 'siarSP', driver='GeoJSON') |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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(sp) | |
library(ggmap) | |
## latticeExtra must be loaded after ggmap because both ggplot2 and | |
## latticeExtra define a 'layer' function. We need the definition from | |
## latticeExtra. | |
library(latticeExtra) | |
## We only need maptools to get an example | |
library(maptools) | |
SIDS <- readShapePoly(system.file("shapes/sids.shp", package="maptools")[1], | |
IDvar="FIPSNO", |
OlderNewer