Description Usage Arguments Value Author(s) See Also Examples
Factorizes one or several integer
s into prime factors.
The obvious prime factor 1 is always excluded, which means that
primeFactors(1) == NULL
.
Note that the current implementation is not very efficient and could most likely be improved.
1 | primeFactors(x, unique=FALSE)
|
x |
A |
unique |
If |
If a single value is given a vector
of prime factors are returned.
If a vector
is given a list
of vectors containing prime factors are
returned.
Henrik Bengtsson
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | x <- 2*2*2*3
print( primeFactors(x) )
print( allFactors(x) )
# 2 2 2 3
# 2 3 4 6 8 12 24
x <- 1
print( primeFactors(x) )
print( allFactors(x) )
# NULL
# NULL
x <- 132319
print( primeFactors(x) )
print( allFactors(x) )
# 11 23 523
# 11 23 253 523 5753 12029
x <- 3128392
print( primeFactors(x) )
print( allFactors(x) )
# 2 2 2 391049
# 2 4 8 391049 782098 1564196
x <- 1:10
str( primeFactors(x) )
# Gives a list of 10 vectors of (non-unique) prime factors
# List of 10
# $ 1 : NULL
# $ 2 : num 2
# $ 3 : num 3
# $ 4 : num [1:2] 2 2
# $ 5 : num 5
# $ 6 : num [1:2] 2 3
# $ 7 : num 7
# $ 8 : num [1:3] 2 2 2
# $ 9 : num [1:2] 3 3
# $ 10: num [1:2] 2 5
str( allFactors(x) )
# Gives a list of 10 vectors of (unique) integer factors.
# Note that obvious factors are excluded, meaning that factorizing
# primes will result in an empty vector.
# List of 10
# $ 1 : NULL
# $ 2 : NULL
# $ 3 : NULL
# $ 4 : num 2
# $ 5 : NULL
# $ 6 : num [1:2] 2 3
# $ 7 : NULL
# $ 8 : num [1:2] 2 4
# $ 9 : num 3
# $ 10: num [1:2] 2 5
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.