[R] nmax parameter in factor function

Ramnik Bansal ramnik.bansal at gmail.com
Sun Jun 4 03:14:20 CEST 2017


I have been trying to understand how the argument 'nmax' works in
'factor' function. R-Documentation states - "Since factors typically
have quite a small number of levels, for large vectors x it is helpful
to supply nmax as an upper bound on the number of unique values."

In the code below what is the reason for error when value of nmax is
24. Why did the same error not occur with nmax = 25  and also how come
there are 26 levels when nmax = 25 ?

> factor(x = letters, nmax = 26)
 [1] a b c d e f g h i j k l m n o p q r s t u v w x y z
Levels: a b c d e f g h i j k l m n o p q r s t u v w x y z

> factor(x = letters, nmax = 25)
 [1] a b c d e f g h i j k l m n o p q r s t u v w x y z
Levels: a b c d e f g h i j k l m n o p q r s t u v w x y z

> factor(x = letters, nmax = 24)
Error in unique.default(x, nmax = nmax) : hash table is full



More information about the R-help mailing list