Learn R Programming

mt (version 2.0-1.20)

dat.sel: Generate Pairwise Data Set

Description

Generate index or data set of pairwise combination based on class labels.

Usage

combn.pw(cls, choices = NULL) 
  
  dat.sel(dat, cls, choices = NULL)

Value

combn.pw returns a data frame of index (logical values).

dat.set returns a list of list with components:

dat

Pairwise data set.

cls

Pairwise class label.

Arguments

dat

A data frame or matrix of data set.

cls

A factor or vector of class labels or categorical data.

choices

The vector or list of class labels to be chosen for binary combination.

Author

Wanchang Lin

Details

If choices is NULL, all binary combinations will be computed. If choices has one class label, the comparisons between this one and any other classes will be calculated. If choices has more than two classes, all binary combinations in choices will be generated. For details, see examples below.

See Also

Applications of dat.sel in pca_plot_wrap, lda_plot_wrap and pls_plot_wrap.

Examples

Run this code
data(iris)
x <- subset(iris, select = -Species)
y <- iris$Species
 
## generate data set with class "setosa" and "virginica"
binmat.1 <- dat.sel(x,y,choices=c("setosa","virginica"))
names(binmat.1)

## generate data sets for "setosa" vs other classes. These are: 
## "setosa" and "versicolor", "setosa" and "virginica".
binmat.2 <- dat.sel(x,y,choices=c("setosa"))
names(binmat.2)

## generate data set with combination of each class. These are:  
## "setosa" and "versicolor", "setosa" and "virginica",  
## "versicolor" and "virginica" 
binmat.3 <- dat.sel(x,y,choices= NULL)
names(binmat.3)

data(abr1)
cls <- factor(abr1$fact$class)
dat <- preproc(abr1$pos, method="log")

## There are some examples of 'choices'
choices <- c("2")
choices <- c("2","3","4")
choices <- list(c("2","3"),c("4","5"))
choices <- NULL
idx <- combn.pw(cls,choices=choices)  

dat.pw <- dat.sel(dat, cls,choices=choices)

Run the code above in your browser using DataLab