Skip to content

Instantly share code, notes, and snippets.

View djhurio's full-sized avatar

Mārtiņš Liberts djhurio

View GitHub Profile
### Apsekojumu statistika
### Praktiskie darbi 2
# Direktorija datiem
# Pirmajā reizē ir jāizveido
dir.data <- "~/ApsStat/Data"
# Saite uz datu failu
file.data <- file.path("http://home.lu.lv/~pm90015/work/LU",
"ApsekojumuStatistika/Data/Population.Rdata")
@djhurio
djhurio / gist:7126a428ab91cf86811f
Created June 29, 2015 16:19
Izvelk ciema vai pilsētas nosaukumu no adreses
extr.ciems <- function(adr_txt) {
# Konvertē visu uz mazajiem burtiem
adr_txt <- tolower(adr_txt)
# Teksta fragmenti, kas neder
pattern <- " nov| pag|\"|[0-9]|\\."
# Sadala adresi pa fragmentiem, izvēlas derīgos, apgriež otrādi un paņem 1.
x <- sapply(strsplit(adr_txt, split = ", "),
function(txt) trim(rev(grep(pattern, txt,
value = T, invert = T))[1]))
# Izlabo kļūdu, kad beidzas ar ā
@djhurio
djhurio / R plot Google Map
Last active March 12, 2016 23:55
Plotting in R on Google Maps
### Plotting in R on Google Maps
require(ggmap)
require(data.table)
### 1 ###
# If you have coordinates available, go to 2
# This is a way how to get some coordinates
@djhurio
djhurio / Optimal Sample Allocation
Created August 3, 2014 18:21
Optimal Sample Allocation in case of non-response
# Optimal Sample Allocation in case of non-response
require(ggplot2)
# 3D Scatterplot
require(rgl)
require(foreach)
require(doMC)
registerDoMC(cores = detectCores())