Habe heute einen kurzen R Benchmark gemacht, bei der ein data.frame mit 7,7 Millionen Zeilen erweitert wird. Dabei habe ich einmal den eingebauten within verwendet und ein anderes mal die Funktion dplyr::mutate.
Der within Code:
logdata <- within(logdata, { YEAR <- as.numeric(format(logdata$timestamp, "%Y")) MONTH <- as.numeric(format(logdata$timestamp, "%m")) WEEK <- as.numeric(format(logdata$timestamp, "%V")) DOM <- as.numeric(format(logdata$timestamp, "%d")) DOW <- ifelse((DOW = as.numeric(format(logdata$timestamp, "%w"))) == 0, 7, DOW) HOUR <- as.numeric(format(logdata$timestamp, "%H"))})
Der dplyr::mutate Code:
logdata <- logdata %>% mutate( YEAR = as.numeric(format(timestamp, "%Y")), MONTH = as.numeric(format(timestamp, "%m")), WEEK = as.numeric(format(timestamp, "%V")), DOM = as.numeric(format(timestamp, "%d")), DOW = ifelse((DOW = as.numeric(format(timestamp, "%w"))) == 0, 7, DOW), HOUR = as.numeric(format(timestamp, "%H")))
Durchschnittliches Laufzeitverhalten nach jeweils 10 Durchgängen:
mutate: 36s within: 31s
Bleibe bei dieser Umwandlung erst einmal bei within.
Hardware: MacBook Pro (Retina 13 Zoll, Anfang 2015); 3,1 GHz Intel Core i7; 16 GB 1867 MHz DDR3
OS: macOS 10.11.6
R: version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
dplyr: version 0.5.0
Geschrieben von sascha am 29. Januar 2017 22:32:08 CET