Learn R Programming

sgr (version 1.3.1)

rdatarepl: Random replacements of data.

Description

Replaces data in the original data matrix using a specified replacement matrix.

Usage

rdatarepl(Dx, RM, printfp = TRUE)

Arguments

Dx

Data frame or matrix to be replaced.

RM

Replacement matrix.

printfp

Logical, if TRUE (the default), it prints the percentage of data replaced.

Value

Returns a list with two elements:

Fx

The replaced (fake) data matrix.

Fperc

Percentage of replaced data.

Details

Replacement matrices can be obtained from the replacement.matrix function.

See Also

replacement.matrix

Examples

Run this code
# NOT RUN {
require(MASS)
set.seed(20130207)
Dx <- rdatagen(R=matrix(c(1,.3,.3,1),2,2),Q=5)$data
RM <- replacement.matrix(p=c(.6,0))
Fx <- rdatarepl(Dx,RM)$Fx

par(mfrow=c(2,2))
for (j in 1:ncol(Dx)) barplot(table(Dx[,j]),main="original data")
for (j in 1:ncol(Fx)) barplot(table(Fx[,j]),main="replaced data")
# }

Run the code above in your browser using DataLab