Learn R Programming

SSBtools (version 1.3.0)

DummyDuplicated: Duplicated columns in dummy matrix

Description

The algorithm is based on crossprod(x) or crossprod(x, u) where u is a vector of random numbers

Usage

DummyDuplicated(x, idx = FALSE, rows = FALSE, rnd = FALSE)

XprodRnd(x, duplic = TRUE, idx = FALSE, rows = FALSE, seed = NULL)

Arguments

x

A matrix

idx

Indices returned when TRUE

rows

Duplicated rows instead when TRUE

rnd

Algorithm based on cross product with random numbers when TRUE (dummy matrix not required)

duplic

XprodRnd parameter: When duplic and idx are FALSE, this function returns crossprod(x,u) or x%*%u instead of indices or duplicated.

seed

XprodRnd parameter: Seed to be used. When NULL the ordinary random value stream in R continues.

Value

Logical vectors specifying duplicated columns or vector of indices (first match)

Details

The efficiency of the default algorithm depends on the sparsity of crossprod(x). The random values are generated locally within the function without affecting the random value stream in R.

Examples

Run this code
# NOT RUN {
x <- cbind(1, rbind(diag(2), diag(2)), diag(4)[, 1:2])
z <- Matrix(x[c(1:4, 2:3), c(1, 2, 1:5, 5, 2)])

DummyDuplicated(z)
which(DummyDuplicated(z, rows = TRUE))

# Four ways to obtain the same result
DummyDuplicated(z, idx = TRUE)
DummyDuplicated(z, idx = TRUE, rnd = TRUE)
DummyDuplicated(t(z), idx = TRUE, rows = TRUE)
DummyDuplicated(t(z), idx = TRUE, rows = TRUE, rnd = TRUE)

# The unique values in four ways 
which(!DummyDuplicated(z), )
which(!DummyDuplicated(z, rnd = TRUE))
which(!DummyDuplicated(t(z), rows = TRUE))
which(!DummyDuplicated(t(z), rows = TRUE, rnd = TRUE))
# }

Run the code above in your browser using DataLab