Skip to content

Instantly share code, notes, and snippets.

View hilaryparker's full-sized avatar

Hilary Parker hilaryparker

View GitHub Profile
@kbroman
kbroman / sprintf_fix.R
Created March 21, 2013 23:04
R function to deal with sprintf("%.2f", ...) returning -0.00
# a function to deal with sprintf("%.2f", ...) returning -0.00
# see https://twitter.com/hspter/status/314858331598626816
f <- function(..., dig=2) {
g <- sprintf(paste0("%.", dig, "f"), ...)
z <- paste0("0.", paste(rep("0", dig), collapse=""))
g[g==paste0("-",z)] <- z
g
}