The function encode4int converts each element in a given integer vector to a binary number.
encode4int(x, M, ...)
A vector containing integer numbers
A vector containing the number of bits in the binary representation of each integer variable.
Further arguments passed to or from other methods.
A vector of binary representation of input vector
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.
# 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