Learn R Programming

crank (version 1.1-2)

meanranks: Calculate mean ranks with possible missing values

Description

Calculates mean ranks where some ranks may be missing

Usage

meanranks(x,allranks=NULL,labels=NULL,rankx=FALSE)

Arguments

x

A matrix of ranks that may contain ties and NAs. Objects ranked are assumed to be columns and ranking methods rows.

allranks

An optional list of all ranks that might have been made.

labels

Optional labels for the ranks.

rankx

Whether to convert competition ranks, or any other set of numeric values, into the usual mean rankings for ties.

Value

A list with the following components:

ranks

x with any NAs replaced by the mean of unallocated ranks for each row.

labels

The vector of labels, defaulting to the integers 1:allranks.

mean.ranks

A vector of mean ranks for each value of allranks.

Details

meanranks calls muranks to complete the rank matrix before calculating the mean ranks for each column if there are any NAs in x.

Note that cats2ranks interprets each value in x as a nominal level variable and its index as the rank, while meanranks interprets values as ordinal level (ranks). Thus if a matrix or data frame of category labels is passed to meanranks, it will not give the correct mean ranks.

See Also

muranks, rank, cats2ranks

Examples

Run this code
# NOT RUN {
 # simulate "best/worst" ranking
 x<-matrix(NA,nrow=10,ncol=10)
 for(i in 1:10) {
  nbest<-sample(2:5,1)
  best<-1:nbest
  nworst<-sample(1:5,1)
  worst<-(11-nworst):10
  rankpos<-sample(1:10,nbest+nworst)
  x[i,rankpos]<-c(best,worst)
 }
 x
 meanranks(x)
# }

Run the code above in your browser using DataLab