force.percentage {NCmisc} | R Documentation |
Sometimes it is nice to be able to take a percentage as an argument and not have to specify whether it should be entered as a number between 0 and 100, e.g, 50 = 50 than 1 and less than 100 will be divided by 100. Anything outside 0,100 will be set to 0,100 respectively.
force.percentage(x, default = 0.5)
x |
the object to ensure is a oercentage |
default |
the value to revert to if the format of x is illegal |
the object x if already legal, first element if a vector, the min or max value if x is outside the specified bounds, or the value of default otherwise
# create variables of different types to show output styles #
force.percentage(45)
force.percentage(450)
force.percentage(.45)
force.percentage(-45)
force.percentage("twenty")
force.percentage(NA,default=0.25)