Learn R Programming

setweaver (version 1.0.0)

prob: prob

Description

Computes the marginal probability \(P(X = 1)\) for a binary vector `x`, ignoring missing values.

Usage

prob(x)

Value

A numeric scalar giving the proportion of entries equal to 1 among the non-missing values of `x`.

Arguments

x

A numeric or logical vector coded as 0/1 (or `FALSE`/`TRUE`). Values other than 0, 1, `FALSE`, `TRUE`, or `NA` will be ignored.

Examples

Run this code
prob(c(0, 1, 1, 0, 1))

Run the code above in your browser using DataLab