Learn R Programming

rimu (version 0.6)

as.ms: Construct scored or ranked multiple-response objects

Description

The internal representation is as a numeric matrix with 0 when a level is not present and the non-zero rank or score when it is present. The data.frame and matrix methods uses the numeric values of x, and by default set NA values to 'not present'. The list method takes a list with a character vector for each observation and uses the position in the list as the rank/score. The character method splits the string at the separators to give a list and uses the list method. The mr method uses a score of 1 whenever the level is present.

Usage

as.ms(x, ...)
# S3 method for list
as.ms(x,...,levels=NULL)
# S3 method for data.frame
as.ms(x,...,na.rm=TRUE)
# S3 method for matrix
as.ms(x,...,na.rm=TRUE)
# S3 method for mr
as.ms(x,...)
# S3 method for character
as.ms(x,sep=", ", ...,levels=NULL)

Value

Object of class ms

Arguments

x

object to be converted

...

for compatibility; not used.

levels

Optional character vector giving the permitted levels

na.rm

Convert NA values to 'not present', ie, 0

sep

Regular expression for splitting the character string

Examples

Run this code

nzbirds_list<-list(c("kea","tui"), c("kea","ruru","kaki"), c("ruru"),
c("tui","ruru"), c("tui","kea","ruru"), c("tauhou","kea"))
nzbirds_list
(msbirds<-as.ms(nzbirds_list))

(bird_mat <- unclass(msbirds))
as.ms(bird_mat)

Run the code above in your browser using DataLab