添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
  • elapsed: Elapsed dates (monthly, quarterly)
  • fill_gap: Add rows corresponding to gaps in some variable
  • is.panel: Check whether a data.frame is a panel
  • join: Join two data frames together
  • n_narm: Count number of non missing observations
  • pctile: Weighted quantile of type 2 (similar to Stata _pctile)
  • statar: A package for applied research
  • stat_binmean: Plot the mean of y over the mean of x within bins of x.
  • sum_up: Gives summary statistics (corresponds to Stata command...
  • tab: Returns cross tabulation
  • tempname: Create unique names within a list, a data.frame, or an...
  • tlead-tlag: lead and lag with respect to a time variable
  • winsorize: Winsorize a numeric vector
  • xtile: Bin variable in groups (similar to Stata xtile)
  • Browse all...
  • Bin variable in groups (similar to Stata xtile)

    Description

    Bin variable in groups (similar to Stata xtile)

    Usage

    xtile(x, n = NULL, probs = NULL, cutpoints = NULL, wt = NULL)
    

    Arguments

    A vector

    A numeric specifying number of quantiles. Can be used instead of cutpoints

    probs

    A vector of probabilities that an be used instead of cutpoints. Quantiles are computed as the inverse of the empirical distribution function (type = 1)

    cutpoints

    Cutpoints to use when nq is not specified. For instance cutpoints = 0.4 creates two groups, one for observations equal or below 0.4, one for observations superior to 0.4.

    A variable specifying weight in case the option n_quantiles is specified.

    Value

    An integer vector representing groups corresponding to cutpoints. Includes missing values when present in the original vector.

    Examples

    x <- c(NA, 1:10)                   
    xtile(x, n = 3) # 3 groups based on terciles
    xtile(x, probs = c(0.3, 0.7)) # 3 groups based on two quantiles
    xtile(x, cutpoints = c(2, 3)) # 3 groups based on two cutpoints