| Title: | Functions and Datasets for Math Used in School |
|---|---|
| Description: | Contains functions for math taught in school. A main focus is set to prime-calculation. The package also contains a dataset of all primes between 1 and 99,999,999. |
| Authors: | Jörg große Schlarmann [aut, cre] |
| Maintainer: | Jörg große Schlarmann <[email protected]> |
| License: | GPL (>= 2) |
| Version: | 0.5.1 |
| Built: | 2026-09-26 09:51:51 UTC |
| Source: | https://github.com/produnis/schoolmath |
cancel a fraction to the smallest numbers
cancel.fraction(numerator, denominator)cancel.fraction(numerator, denominator)
numerator |
the fraction's numerator |
denominator |
the fraction's denominator #' |
An integer vector of length 2 containing the reduced numerator and denominator.
cancel.fraction(40,15) cancel.fraction(42, 56)cancel.fraction(40,15) cancel.fraction(42, 56)
convert a decimal-number into fraction
decimal2fraction(decimal, period = 0)decimal2fraction(decimal, period = 0)
decimal |
the decimal number to be converted, given without an repeating ending |
period |
if the decimal places have an repeating ending (period), set the period here. See examples. #' |
An integer vector of length 2 containing the numerator and denominator
## converting 23.4323 decimal2fraction(23.4323) ## converting a number with decimal period, e.g. 12.12344444444444444444 decimal2fraction(12.123, 4)## converting 23.4323 decimal2fraction(23.4323) ## converting a number with decimal period, e.g. 12.12344444444444444444 decimal2fraction(12.123, 4)
Greatest common divisor of two numbers
gcd(x, y)gcd(x, y)
x |
first number |
y |
second number #' |
numeric greatest common divisor
gcd(42, 56)gcd(42, 56)
checks if a number is decimal or integer and returns TRUE for decimal
is.decimal(x)is.decimal(x)
x |
a vector with numbers to check #' |
true or false
is.decimal(40.15) # will return TRUE is.decimal(4015) # will return FALSEis.decimal(40.15) # will return TRUE is.decimal(4015) # will return FALSE
Checks whether numbers are even.
is.even(x)is.even(x)
x |
A numeric vector. |
A logical vector of the same length as 'x'.
is.even(45) # will return FALSE is.even(46) # will return TRUE is.even(46.2) # will return FALSE x <- c(1, 2, 3, 4, 5, 6, 7, 8.4) is.even(x)is.even(45) # will return FALSE is.even(46) # will return TRUE is.even(46.2) # will return FALSE x <- c(1, 2, 3, 4, 5, 6, 7, 8.4) is.even(x)
Check whether numbers are negative.
is.negative(x)is.negative(x)
x |
A numeric vector. |
A logical vector of the same length as 'x'.
is.negative(3) # FALSE is.negative(0) # FALSE is.negative(-2) # TRUE x <- c(-1, -2, 3.02, 4, -5.2, 6, -7) is.negative(x)is.negative(3) # FALSE is.negative(0) # FALSE is.negative(-2) # TRUE x <- c(-1, -2, 3.02, 4, -5.2, 6, -7) is.negative(x)
Checks whether numbers are odd.
is.odd(x)is.odd(x)
x |
A numeric vector. |
A logical vector of the same length as 'x'.
is.odd(45) # will return TRUE is.odd(46) # will return FALSE is.odd(45.123) # will return FALSE x <- c(1, 2, 3, 4, 5, 6, 7, 8, 9.7) is.odd(x)is.odd(45) # will return TRUE is.odd(46) # will return FALSE is.odd(45.123) # will return FALSE x <- c(1, 2, 3, 4, 5, 6, 7, 8, 9.7) is.odd(x)
Check whether numbers are positive.
is.positive(x)is.positive(x)
x |
A numeric vector. |
A logical vector of the same length as 'x'.
is.positive(3) # TRUE is.positive(-2) # FALSE is.positive(0) # FALSE x <- c(-1, -2, 3.02, 4, -5.2, 6, -7, 0) is.positive(x)is.positive(3) # TRUE is.positive(-2) # FALSE is.positive(0) # FALSE x <- c(-1, -2, 3.02, 4, -5.2, 6, -7, 0) is.positive(x)
Check whether a vector contains prime numbers
is.prim(x)is.prim(x)
x |
The number or vector to check. |
A logical vector indicating whether values are prime.
is.prim(8) is.prim(11) x <- c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11) is.prim(x)is.prim(8) is.prim(11) x <- c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11) is.prim(x)
A real positive number is defined here as a number greater than or equal to zero.
is.real.positive(x)is.real.positive(x)
x |
A numeric vector. |
A logical vector of the same length as 'x'.
is.real.positive(-3) # FALSE is.real.positive(0) # TRUE x <- c(0, -1, -2, 3.02, 4, -5.2, 6, -7) is.real.positive(x)is.real.positive(-3) # FALSE is.real.positive(0) # TRUE x <- c(0, -1, -2, 3.02, 4, -5.2, 6, -7) is.real.positive(x)
checks if a number is decimal or integer and returns FALSE for decimal
is.whole(x)is.whole(x)
x |
a vector with numbers to check #' |
true or false
is.whole(40.15) # will return FALSE is.whole(4015) # will return TRUEis.whole(40.15) # will return FALSE is.whole(4015) # will return TRUE
This function calculates the prime-factors of a number
prime.factor(n)prime.factor(n)
n |
the number to be checked #' |
a vector with the prime factors
prime.factor(21) prime.factor(100)prime.factor(21) prime.factor(100)
generate prime-numbers in a range from START to END
primes(start = 1, end = 9999, live = FALSE)primes(start = 1, end = 9999, live = FALSE)
start |
the number to start from |
end |
the number to end |
live |
should primes additionally be printed out to stdout when found? (default is FALSE) |
a vector of prime numbers
primes(12,150) # list prime-numbers between 12 and 150primes(12,150) # list prime-numbers between 12 and 150
Contains primes between 1 and 99,999,999
data(primlist)data(primlist)
A vector containing primes between 1 and 99,999,999
Variables in the dataset:
primlist. A vector containing primes between 1 and 99,999,999
calculating the smallest common multiple of two numbers
scm(x, y)scm(x, y)
x |
first number |
y |
second number #' |
numeric least common multiple
scm(3528, 3780)scm(3528, 3780)