Learn R Programming

MSMU (version 0.1.2)

pct: Percent Within N Standard Deviations of the Mean

Description

Calculates the percentage of values in a numeric vector that fall within n standard deviations of the mean.

Usage

pct(x, n)

Value

A single numeric value representing the percentage (0–100) of values within the specified range.

Arguments

x

A numeric vector.

n

A positive numeric value indicating how many standard deviations from the mean to use as bounds.

Examples

Run this code
# Percentage of values that fall within 2 sds of the mean in random normal data
set.seed(123)
x <- rnorm(1000)
pct(x,2)

# Percentage of values that fall within 2 sds of the mean in iris Sepal Lengths
data("iris")
pct(iris$Sepal.Length, 2)


Run the code above in your browser using DataLab