R version 4.5.0 beta (2025-04-01 r88091 ucrt) -- "How About a Twenty-Six" Copyright (C) 2025 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > > library(nanotime) > > set.seed(42) > N <- 300 > shine <- nanotime(Sys.time()) + cumsum(10*rpois(n=N+1, lambda=4)) > rain <- nanotime(Sys.time()) + cumsum(10*rpois(n=N+1, lambda=4) + round(runif(N+1)*25)) > > if (requireNamespace("data.table", quietly=TRUE)) { + suppressMessages(library(data.table)) + suppressMessages(library(bit64)) + raw <- data.table(shine=shine, rain=rain) + + df <- data.frame(val=c(rain,shine), key=rep(c("rain", "shine"), each=N+1)) + head(df) + + ## now on differences + ddf <- data.frame(val=as.numeric(c(diff(rain),diff(shine))), # need to cast to numeric after diffs + key=rep(c("rain", "shine"), each=N)) + head(ddf) + + ## simpler data.frame, inserts 'formatted' + newdf <- data.frame(rain=rain, shine=shine) + head(newdf) + } rain shine 1 2025-04-02T12:32:16.214564144+00:00 2025-04-02T12:32:16.211693118+00:00 2 2025-04-02T12:32:16.214564162+00:00 2025-04-02T12:32:16.211693188+00:00 3 2025-04-02T12:32:16.214564205+00:00 2025-04-02T12:32:16.211693218+00:00 4 2025-04-02T12:32:16.214564277+00:00 2025-04-02T12:32:16.211693278+00:00 5 2025-04-02T12:32:16.214564366+00:00 2025-04-02T12:32:16.211693328+00:00 6 2025-04-02T12:32:16.214564400+00:00 2025-04-02T12:32:16.211693368+00:00 > > proc.time() user system elapsed 1.04 0.20 1.23