R/FSAUtils.R
perc.RdComputes the percentage of values in a vector less than or greater than (and equal to) a user-supplied value.
perc( x, val, dir = c("geq", "gt", "leq", "lt"), na.rm = TRUE, digits = getOption("digits") )
| x | A numeric vector. |
|---|---|
| val | A single numeric value. |
| dir | A string that indicates whether the percentage is for values in |
| na.rm | A logical that indicates whether |
| digits | A single numeric that indicates the number of decimals the percentage should be rounded to. |
A single numeric that is the percentage of values in x that meet the criterion in dir relative to val.
This function is most useful when used with an apply-type of function.
Derek H. Ogle, derek@derekogle.com
#> [1] 1 2 3 4 5 6 7 8 NA NA## percentages excluding NA values perc(tmp,5)#> [1] 50perc(tmp,5,"gt")#> [1] 37.5perc(tmp,5,"leq")#> [1] 62.5perc(tmp,5,"lt")#> [1] 50## percentages including NA values perc(tmp,5,na.rm=FALSE)#> [1] 40perc(tmp,5,"gt",na.rm=FALSE)#> [1] 30perc(tmp,5,"leq",na.rm=FALSE)#> [1] 50perc(tmp,5,"lt",na.rm=FALSE)#> [1] 40