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
# Source: the masterful Marc Schwartz, in this R-help thread: | |
# http://r.789695.n4.nabble.com/previous-monday-date-td3786395.html | |
# Getting the Monday preceding any date | |
# See ?cut.Date for additional info | |
as.Date(cut(Sys.Date(), breaks = "weeks")) | |
# Alternatively, the preceding Sunday: | |
as.Date(cut(Sys.Date(), breaks = "weeks", start.on.monday = FALSE) |
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
# An alternative approach | |
# First - a quick function for counting unique values that excludes NAs | |
count.unique <- function(x) { length(unique(x[!is.na(x)])) } | |
# Compare: | |
length(unique(NA)) | |
count.unique(NA) | |