This file contains 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("lubridate") | |
#> | |
#> Attaching package: 'lubridate' | |
#> The following object is masked from 'package:base': | |
#> | |
#> date | |
a_sunday <- as.Date("2017-08-27") | |
# floor_date rounds to Sunday: |
This file contains 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
class Dojo: | |
def __init__(self, input): | |
self.input = input | |
def calculate(self): | |
return 42 |
This file contains 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
# open Rproj with packrat | |
# restart R session | |
library("testthat") | |
source("libraries.R") | |
packrat::with_extlib( | |
c("rex", "covr", "DT"), { | |
library("rex") | |
library("covr") |
This file contains 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
var TennisGame1 = function(player1Name, player2Name) { | |
this.scores = [ | |
0, | |
0 | |
]; | |
this.players = [ | |
player1Name, | |
player2Name | |
]; |
This file contains 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
# dt is a data.table with id_cols and value_cols | |
# we want rows where any of the value cols is not NA regardless of the | |
# values of the id_cols | |
dt[, to_keep := purrr::pmap_lgl( | |
purrr::map_df( | |
dt[, .SD, .SDcols = value_cols], | |
~ !is.na(.x) | |
), | |
any |
This file contains 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("xts") | |
dt <- data.table( | |
day = seq.Date(as.Date('2016-07-01'), by = 'day', length.out = 180), | |
x = 1:180, | |
y = 1001:1180 | |
) | |
ts_data <- as.xts(dt) |
This file contains 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
dt <- data.table(x = c(4,4,2,5,4,2,3)) | |
dt[, g := .GRP, by = x] | |
dt[, cumuniquen := cummax(g)] |
NewerOlder