ntiles | R Documentation |
The data of a variable are rank-ordered and split to bins of (approximately) equal size. When tied ranks span across category borders, the function assigns all values to the lowest possible bin. This procedure can result in slightly different results as the corresponding function Rank Cases
of SPSS with option Ntiles
.
ntiles(data, dv, factors = NaN, bins = 5, res.labels = FALSE)
data |
A data frame containing the data relevant variable and possible factors that can be used to split the data frame into separate compartments. |
dv |
Character string specifying the name of the variable within |
factors |
A string or vector of strings (e.g., |
bins |
The number of bins to be generated. Alternatively, a vector of cut-points can be specified according to the |
res.labels |
The default value |
ntiles(data, dv, ...)
returns a vector of bins.
Roland Pfister; Markus Janczyk
cut
; rank
; split
; lapply
;
## Build data frame var1 <- c(1:9) var2 <- c(1,1,1,2,2,2,3,3,3) tmpdata <- data.frame(cbind(var1,var2)) tmpdata$var2 <- as.factor(tmpdata$var2) ## Get overall bins and display result tmpdata$bins <- ntiles(tmpdata, dv = "var1", bins=3) tmpdata ## Get bins separately for each factor level ## and display result tmpdata$bins2 <- ntiles(tmpdata, dv = "var1", bins=3, factors = "var2") tmpdata
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.