Description Usage Arguments Details Value Author(s) See Also Examples
A function which determines the prevalence or probability for each class of a vector (treated as factor).
1 | classprob(x)
|
x |
a one dimensional vector |
This function treats the input vector as a factor and
determines the probability for each level (class) of the
factor. The order of the returned probabilities is the
order of the levels
command, which defaults
to numeric or alphabetic order.
A vector whose length is equal to the number of levels in the input. The order is numerically or alphabetically increasing. Note the factors may have levels which are not present in the vector, see examples for details.
Atina Dunlap Brooks
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | #calculate probbilities
x <- sample( c("a","b","c","d","e"), 10, replace=TRUE )
classprob(x)
#label the probabilities
levels(as.factor(x))
#to see levels which aren't represnted in the vector
x<-as.factor(c('a','a','a','b','b','c'))
levels(x)
#now remove the 'c'
x<-x[1:5]
#but 'c' is still a level
levels(x)
#and the probability is calculated for it
classprob(x)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.