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
imsbasics::clc() | |
jahr16 <- seq(as.Date("2016/1/1"), as.Date("2016/12/31"), "days") | |
jahr17 <- seq(as.Date("2017/1/1"), as.Date("2017/12/31"), "days") | |
jahr18 <- seq(as.Date("2018/1/1"), as.Date("2018/12/31"), "days") | |
jahr19 <- seq(as.Date("2019/1/1"), as.Date("2019/12/31"), "days") | |
library(testthat) | |
library(lubridate) | |
expect_equal(wday(jahr16[5]), wday(jahr19[1])) | |
expect_equal(wday(jahr17[3]), wday(jahr19[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
osrmr::run_server("switzerland-latest", "C:/OSRM_API5") | |
osrmr::viaroute(47.1, 8.1, 46.9, 8.3, FALSE, 5, TRUE) | |
options(osrm.server = paste0(osrmr:::server_address(TRUE), "/")) | |
getOption("osrm.server") | |
osrm::osrmRoute(src = c("A", 8.1, 47.1), dst = c("B", 8.3, 46.9), sp = TRUE, overview = "full")$duration*60 | |
osrmr::quit_server() |
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
imsbasics::clc() | |
apply_rules <- function(data, rules) { | |
for (i in 1:length(rules)) { | |
rules_now <- unlist(strsplit(rules[i], ", ")) | |
for (j in 1:length(rules_now)) { | |
data[i] <- apply_rule(data[i], rules_now[j]) | |
} | |
} | |
return(data) |
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
# Testdaten | |
df <- data.frame(category = c(1,2,3,1,3,2,1), value = rep(10, 7)) | |
# Variante 1: | |
# Die Klassiker | |
df[df$category == 2,] | |
subset(df, category == 2) | |
# Variante 2: |
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
# Testdaten | |
df <- data.frame(category = c(1,2,3,1,3,2,1), value = rep(10, 7)) | |
# Variante 1: | |
# Falls du nur die Häufigkeit der Einträge der verschiedenen Kaetgorien brauchst: | |
table(df) | |
# value | |
# category 10 | |
# 1 3 |
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
# Error on purpose in line 31-36. Testscript for learning debugging using different options. | |
imsbasics::clc() | |
imsbasics::cc() | |
f1 <- function(a) { | |
# message("Message f1") | |
b <- 10 | |
return(a + 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
set.seed(1) | |
vec <- runif(1000) | |
vec1 <- vec | |
print(paste0("Die beiden Vektoren sind identisch: ", all.equal(vec, vec1))) | |
print(paste0("Die Variante for-loop dauert: ", summary(microbenchmark::microbenchmark( | |
for (i in 1:length(vec)) { | |
if (vec[i] > 0.5) {vec[i] <- 10} | |
} | |
), unit = "ms")$uq, "ms")) |
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(data.table) | |
dt <- data.table(a = c(1:10000), b = rep(c("a","b","c"), length = 10000)) | |
df <- data.frame(a = c(1:10000), b = rep(c("a","b","c"), length = 10000)) | |
microbenchmark::microbenchmark(dt[dt$b == "b",], times = 1000, unit = "us") | |
microbenchmark::microbenchmark(df[df$b == "b",], times = 1000, unit = "us") | |
microbenchmark::microbenchmark(dt$a[dt$b == "b"], times = 1000, unit = "us") | |
microbenchmark::microbenchmark(df$a[df$b == "b"], times = 1000, unit = "us") |