INITIAL SETUP
# turning MHID9870 into a bit string
en <- utf8ToInt("MHID9870")
en <- binary(en, mb=7)
en <- strsplit(en,"")
en <- unlist(en)
en <- as.integer(en)
en
# Separating the bit string into parts
parts <- en
x <- parts[1:19]
y <- parts[20:41]
z <- parts[21:64]
# Finding frequency of each binary bit
my_mode <- function(v){
freq_count <- table(v)
max_idx <- which.max(freq_count)
m <- names(max_idx)
return(m)
}
xyzmaj <- my_mode(c(x[9],y[11],z[11]))
QUESTION STARTS BELOW:
I created the following if-else and for loop statement
variable names: xyzmaj = is the majority bit (0 or 1) between the x,y,z strings my_mode = is a function that takes a string and returns the mode of the string. The variable "x" is a 19 bit long string of bit numbers (0 and 1)
if ( xyzmaj == my_mode(x)) {
for(i in 1:length(x)){
x[i+1] <- x[i]
i <- i+1
}
}
x
my output keeps showing up as
000000000000000000000
I am trying to make it shift right, but the code keeps just taking the first integer and replacing with every integer after.
So basically if X is 010011010101001000010
Output should be 001001101010100100001