Skip to content

Instantly share code, notes, and snippets.

@mwfrost
Created January 17, 2011 19:03
Show Gist options
  • Select an option

  • Save mwfrost/783281 to your computer and use it in GitHub Desktop.

Select an option

Save mwfrost/783281 to your computer and use it in GitHub Desktop.
convert to percentage format
percentify <- function(x, r=1, keep.zeros=FALSE, na.code=""){
ifelse (as.numeric(x) != 0 | keep.zeros==TRUE, paste( format(round ( as.numeric(x) * 100, r) , nsmall=r) , '%', sep='')
,
na.code)
}
# usage example:
sapply(dataframe[3:5], percentify, 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment