allFactors: Factorizes one or several integers into all possible factors

Description Usage Arguments Value Author(s) See Also Examples

View source: R/allFactors.R

Description

Factorizes one or several integers into all possible integer factors, including, but not only, prime factors.

The obvious factors 1 and x are always excluded, which means that allFactors(1) == NULL and allFactors(p) == NULL where $p$ is a prime.

This implementation relies on the primeFactors() function, which currently is not very efficient in certain cases, making this function suffer its slowness.

Usage

1

Arguments

x

A vector of integers to be factorized.

unique

If TRUE the unique set of integer factors are returned otherwise duplicated integer factors might be returned.

Value

If a single value is given a vector of all factors are returned. If a vector is given a list of vectors containing all factors are returned.

Author(s)

Henrik Bengtsson

See Also

primeFactors()

Examples

 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

HenrikBengtsson/R.basic documentation built on May 6, 2019, 11:51 p.m.