| breakfactor | R Documentation | 
Generates a factor encoding the segmentation given by a set of breakpoints.
breakfactor(obj, breaks = NULL, labels = NULL, ...)
obj | 
 An object of class   | 
breaks | 
 an integer specifying the number of breaks
to extract (only if   | 
labels | 
 a vector of labels for the returned factor,
by default the segments are numbered starting from
  | 
... | 
 further arguments passed to   | 
A factor encoding the segmentation.
breakpoints
## Nile data with one breakpoint: the annual flows drop in 1898
## because the first Ashwan dam was built
data("Nile")
plot(Nile)
## compute breakpoints
bp.nile <- breakpoints(Nile ~ 1)
## fit and visualize segmented and unsegmented model
fm0 <- lm(Nile ~ 1)
fm1 <- lm(Nile ~ breakfactor(bp.nile, breaks = 1))
lines(fitted(fm0), col = 3)
lines(fitted(fm1), col = 4)
lines(bp.nile, breaks = 1)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.