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
```{r data_load, warning=FALSE, echo=FALSE, cache=FALSE} | |
actual.data <- load.finrisk(fields) | |
``` | |
```{r rows_per_year, echo=TRUE, cache=FALSE} | |
# How many rows for each year | |
manual.data <- c(rep(1992, 6031), rep(1997, 8350), rep(2002, 8491), rep(2007, 6115)) | |
manual.df <- data.frame(VAR1=manual.data) | |
table(manual.df$VAR1) |
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(pxR) | |
# Finish municipal election data from Statistics Finland | |
good.px.url <- "http://pxweb2.stat.fi/database/StatFin/vaa/kvaa/2008_05/610_kvaa_2008_2009-10-30_tau_137_fi.px" | |
bad.px.url <- "http://pxweb2.stat.fi/Database/StatFin/vaa/kvaa/2008_04/410_kvaa_2008_2009-11-02_tau_123_fi.px" | |
# Works | |
good.px.object <- read.px(good.px.url) | |
# Crashes R |
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
# -*- coding: utf-8 -*- | |
''' | |
Windows error reporting dialog must be disabled for this to work: | |
1. Press WIN+R | |
2. Type in "gpedit.msc" | |
3. Computer configuration -> Administrative Templates | |
4. Windows Components -> Windows Error Reporting | |
5. Set "Prevent display of the user interface for critical errors" to Enabled | |
''' |
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
.get.format <- Vectorize(function(x) { | |
if (nchar(x) == 4) { | |
return("%H%M") | |
} else if(nchar(x) == 6) { | |
return("%H%M%S") | |
} else { | |
warning(paste("Time String should be either HHMM or HHMMSS:", x)) | |
return(NA) | |
} |
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("sp") | |
library("rgdal") | |
# df is a data frame holding the coords (in ETRS-TM35FIN) in east (easting) and north (northing) fields | |
sp.data <- SpatialPointsDataFrame(df[, c(north, east)], df, proj4string = CRS("+init=epsg:3067")) | |
# Project the spatial data to lat/lon | |
sp.data.wgs84 <- spTransform(sp.data, CRS("+proj=longlat +datum=WGS84")) |
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
# Read in the data | |
dat <- read.csv("...", sep=";", header=T) | |
# Calculate the percentage values for each 10° category | |
# Divide each row n value with the sum of all n's | |
# Round to precision 3, this will cause a slight | |
# rounding error | |
dat$percent <- round(dat$n / sum(dat$n) * 100, 3) | |
# Get just the South-East [90°, 180°] |
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
# KML-filun määrityksen mukaan enkoodaus on UTF-8 | |
> head -n 1 Kuntarajat\ 2011\ \&\ 2012\ .kml | |
<?xml version='1.0' encoding='UTF-8'?> | |
# Fileen oikea enkoodaus on kuitenkin iso-8859-1 | |
> file -bi Kuntarajat\ 2011\ \&\ 2012\ .kml | |
application/xml; charset=iso-8859-1 | |
# Muutetaan enkoodaus iso-8859-1 -> UTF-8 | |
> iconv -f iso-8859-1 -t utf8 Kuntarajat\ 2011\ \&\ 2012\ .kml > Kuntarajat_2011_2012_utf8.kml |
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(reshape) | |
# Generate some toy data | |
df.kemera <- data.frame("Habitat_RL"=c("Mrf", "Mrg", "Ik", "Ij"), | |
"Lehto"=c(0, 1, 0, 0), | |
"Paahde"=c(1, 0, 0, 1), | |
"Lähde"=c(0, 0, 1, 0), | |
"Letto"=c(1, 0, 0, 0)) | |
df.natura <- data.frame("Habitat_RL"=c("Mrf", "Mrg", "Ik", "Ij"), | |
"Heinävarpu"=c(0, 0, 1, 1), |
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
# Install dependencies if not present | |
deps <- c("ggmap", "sp", "rgdal", "XLConnect") | |
install.packages(deps) | |
for (dep in deps) { | |
library(dep, character.only=TRUE) | |
} | |
# Read the data | |
xlsx.file <- "/home/jlehtoma/temp/Points to be converted.xlsx" |
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(plyr) | |
# Generate some data ------------------------------------------------------ | |
set.seed(66) | |
# Define the folder from which to read | |
csv.folder <- "PATH_TO_CSV_FOLDER" | |
# Number of hila elements |