Learn R Programming

MiscMath (version 1.1)

gcd: Greatest Common Divisor

Description

Greatest common divisor or factor for all elements of a positive-integer-valued vector.

Usage

gcd(x)

Value

a numeric constant containing the greatest common divisor.

Arguments

x

a numeric vector consisting of at least two positive integer values.

Details

The gcd is calculated using the Euclidean algorithm applied to successive pairs of the elements of x.

Examples

Run this code
x <- c(81, 57, 333)
gcd(x)

Run the code above in your browser using DataLab