Last data update: 2014.03.03
|
R: Transform a numerical vector to a factor
Transform a numerical vector to a factor
Description
Transform a numerical vector from class POSIXt or Date to a factor.
Usage
num2fac(num, method = "pretty", num_scale = "auto", n = 0, brks = NA)
Arguments
num |
numeric vector
|
method |
-
"pretty" intervals are determined by the base function pretty
-
"kmeans" the method intervals are determined by the method kmeans where n clusters (i.e. intervals) are found
-
"fixed" determines the intervals by the argument brks
-
"discrete" the unique values in num are mapped one to one to the levels of the new factor vector)
|
num_scale |
-
"auto" used scale is determined automatically
-
"lin" num is directly fed to the method pretty or kmeans
-
"log" a logarithmic transformation of num is fed to the method pretty or kmeans
|
n |
the (desired) number of levels. n=0 means automatic
|
brks |
breaks that determine the levels (only required when method="fixed" )
|
Value
A factor vector
Note
This function is still in development stage, and can be improved and optimized. ff vectors are not implemented yet
See Also
datetime2fac
Examples
require(ggplot2)
data(diamonds)
diamonds$price2 <- num2fac(diamonds$price)
tableplot(diamonds)
Results
|