Learn R Programming

tabplot (version 1.3-3)

num2fac: 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

See Also

datetime2fac

Examples

Run this code
# NOT RUN {
require(ggplot2)
data(diamonds)

diamonds$price2 <- num2fac(diamonds$price)

tableplot(diamonds)
# }

Run the code above in your browser using DataLab