File: mutateBits.R

package info (click to toggle)
r-cran-mlr 2.19.2%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 8,264 kB
  • sloc: ansic: 65; sh: 13; makefile: 5
file content (8 lines) | stat: -rw-r--r-- 192 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
# Takes a bit string and flips its elements based on a given mutation rate.
#

mutateBits = function(x, rate = 1 / length(x)) {
  n = length(x)
  flip = rbinom(n, 1, rate)
  (x + flip) %% 2
}