as.mr {rimu}R Documentation

Construct multiple-response objects

Description

Constructs mr objects representing multiple-choice questions where more than one choice is allowed.

Usage

as.mr(x, ...)
## S3 method for class 'logical'
as.mr(x,name,...)
## S3 method for class 'list'
as.mr(x, sort.levels=TRUE,...,levels=NULL)
## S3 method for class 'factor'
as.mr(x, sort.levels=FALSE,...)
## S3 method for class 'data.frame'
as.mr(x, sort.levels=FALSE,...,na.rm=TRUE)
## S3 method for class 'character'
as.mr(x, sep=", ", sort.levels=TRUE,..., levels=NULL)
## Default S3 method:
as.mr(x, sort.levels=TRUE, levels=unique(x),...)
## S3 method for class 'ms'
as.mr(x,...)

Arguments

x

Object to be converted to class mr

...

for compatibility; not used

sort.levels

put the levels of the mr object in increasing sort order. Defaults to TRUE except when there already is a natural order

levels

optional character vector of the permitted levels

name

level name (for a vector) or vector of level names to replace the column names (for a matrix)

na.rm

If TRUE, replace NA in the input by FALSE

sep

Regular expression for splitting the string

Details

The internal representation of mr objects is as a logical matrix with the levels as column names.

The method for logical x coerces a single vector to a one-column matrix, and then applies the name argument as the column name. Given a matrix, the name argument is optional and replaces the existing column names

The method for list x takes a list of character vectors that represent the levels present for one observation. The method for strings splits the string at the supplied separator and then uses the list method.

The method for factor x produces an mr object with the factor levels as levels. Each observation will have only one value.

The data.frame object works for logical or numeric columns of a data frame. Zero or negative values are treated as 'not present', positive values as 'present'. Optionally, NA values are coded as 'not present', which is useful when the data frame was created by reshape or dplyr::spread.

The method for ms objects simply drops the score/rank information

Value

Object of class mr

Examples


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

data(nzbirds)
nzbirds
as.mr(nzbirds)

data(ethnicity)
ethnicity
as.logical(ethnicity)
as.mr(as.logical(ethnicity))



[Package rimu version 0.6 Index]