Learn R Programming

adana (version 1.1.0)

encode4int: Convert integer vectors to binary vectors

Description

The function encode4int converts each element in a given integer vector to a binary number.

Usage

encode4int(x, M, ...)

Arguments

x

A vector containing integer numbers

M

A vector containing the number of bits in the binary representation of each integer variable.

Further arguments passed to or from other methods.

Value

A vector of binary representation of input vector

Details

This function converts each element in the integer vector passed with the x argument to a binary number. The M argument refers to the number of bits in the binary representation of each integer variable.

See Also

decode4int, calcM

Examples

Run this code
# NOT RUN {
n = 5
lb = c(0, 0, 0)
ub = c(10, 10, 10)
set.seed(1)
intmat = matrix(round(runif(3*n, lb, ub)), nr=n, nc=3) 
colnames(intmat) = paste0("v",1:3)
head(intmat)
M = calcM(ub)
M
binmat = matrix(NA, nrow=n, ncol=sum(M))
for(i in 1:n)
  binmat[i,] = encode4int(intmat[i,], M=M)
head(binmat)
# }

Run the code above in your browser using DataLab