R/tfl2spc.R

tfl2spc <- function (tfl)
{
  if (! inherits(tfl, "tfl")) stop("argument must be object of class 'tfl'")
  if (attr(tfl, "incomplete")) stop("incomplete type frequency lists are not supported")

  f <- tfl$f
  if (!is.integer(f)) {
    if (! all(tfl$f == floor(tfl$f))) stop("type frequencies in 'tfl' must be integer values")
    f <- as.integer(f)
  }

  idx <- tfl$f > 0
  f <- if (!all(idx)) tfl$f[idx] else tfl$f
  x <- rle(sort(f))
  spc(Vm=x$lengths, m=x$values)
}

Try the zipfR package in your browser

Any scripts or data that you put into this service are public.

zipfR documentation built on Jan. 8, 2021, 2:37 a.m.