Skip to content

Instantly share code, notes, and snippets.

View oscarperpinan's full-sized avatar

Oscar Perpiñán Lamigueiro oscarperpinan

View GitHub Profile
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
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))]
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