force.percentage: Force argument to be a percentage with length one

View source: R/NCmisc.R

force.percentageR Documentation

Force argument to be a percentage with length one

Description

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.

Usage

force.percentage(x, default = 0.5)

Arguments

x

the object to ensure is a oercentage

default

the value to revert to if the format of x is illegal

Value

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

See Also

force.scalar

Examples

# 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)

NCmisc documentation built on Oct. 17, 2022, 5:09 p.m.