1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
|
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/bit.R
\name{length.bit}
\alias{length.bit}
\alias{length<-.bit}
\alias{length.bitwhich}
\alias{length<-.bitwhich}
\alias{length.ri}
\title{Getting and setting length of bit, bitwhich and ri objects}
\usage{
\method{length}{bit}(x)
\method{length}{bit}(x) <- value
\method{length}{bitwhich}(x)
\method{length}{bitwhich}(x) <- value
\method{length}{ri}(x)
}
\arguments{
\item{x}{a \code{\link{bit}}, \code{\link{bitwhich}} or \code{\link{ri}}
object}
\item{value}{the new number of bits}
}
\value{
the length A bit vector with the new length
}
\description{
Query the number of bits in a \code{\link{bit}} vector or change the number
of bits in a bit vector. \cr Query the number of bits in a
\code{\link{bitwhich}} vector or change the number of bits in a bit vector.
\cr
}
\details{
NOTE that the length does NOT reflect the number of selected (\code{TRUE})
bits, it reflects the sum of both, \code{TRUE} and \code{FALSE} bits.
Increasing the length of a \code{\link{bit}} object will set new bits to
\code{FALSE}. The behaviour of increasing the length of a
\code{\link{bitwhich}} object is different and depends on the content of the
object: \itemize{
\item TRUE -- all included, new bits are set to \code{TRUE}
\item positive integers -- some included, new bits are set to \code{FALSE}
\item negative integers -- some excluded, new bits are set to \code{TRUE}
\item FALSE -- all excluded:, new bits are set to \code{FALSE} } Decreasing the
length of bit or bitwhich removes any previous information about the status
bits above the new length.
}
\examples{
stopifnot(length(ri(1, 1, 32))==32)
x <- as.bit(ri(32, 32, 32))
stopifnot(length(x)==32)
stopifnot(sum(x)==1)
length(x) <- 16
stopifnot(length(x)==16)
stopifnot(sum(x)==0)
length(x) <- 32
stopifnot(length(x)==32)
stopifnot(sum(x)==0)
x <- as.bit(ri(1, 1, 32))
stopifnot(length(x)==32)
stopifnot(sum(x)==1)
length(x) <- 16
stopifnot(length(x)==16)
stopifnot(sum(x)==1)
length(x) <- 32
stopifnot(length(x)==32)
stopifnot(sum(x)==1)
x <- as.bitwhich(bit(32))
stopifnot(length(x)==32)
stopifnot(sum(x)==0)
length(x) <- 16
stopifnot(length(x)==16)
stopifnot(sum(x)==0)
length(x) <- 32
stopifnot(length(x)==32)
stopifnot(sum(x)==0)
x <- as.bitwhich(!bit(32))
stopifnot(length(x)==32)
stopifnot(sum(x)==32)
length(x) <- 16
stopifnot(length(x)==16)
stopifnot(sum(x)==16)
length(x) <- 32
stopifnot(length(x)==32)
stopifnot(sum(x)==32)
x <- as.bitwhich(ri(32, 32, 32))
stopifnot(length(x)==32)
stopifnot(sum(x)==1)
length(x) <- 16
stopifnot(length(x)==16)
stopifnot(sum(x)==0)
length(x) <- 32
stopifnot(length(x)==32)
stopifnot(sum(x)==0)
x <- as.bitwhich(ri(2, 32, 32))
stopifnot(length(x)==32)
stopifnot(sum(x)==31)
length(x) <- 16
stopifnot(length(x)==16)
stopifnot(sum(x)==15)
length(x) <- 32
stopifnot(length(x)==32)
stopifnot(sum(x)==31)
x <- as.bitwhich(ri(1, 1, 32))
stopifnot(length(x)==32)
stopifnot(sum(x)==1)
length(x) <- 16
stopifnot(length(x)==16)
stopifnot(sum(x)==1)
length(x) <- 32
stopifnot(length(x)==32)
stopifnot(sum(x)==1)
x <- as.bitwhich(ri(1, 31, 32))
stopifnot(length(x)==32)
stopifnot(sum(x)==31)
message("NOTE the change from 'some excluded' to 'all excluded' here")
length(x) <- 16
stopifnot(length(x)==16)
stopifnot(sum(x)==16)
length(x) <- 32
stopifnot(length(x)==32)
stopifnot(sum(x)==32)
}
\seealso{
\code{\link{length}}, \code{\link[=sum.bit]{sum}},
\code{\link{poslength}}, \code{\link{maxindex}}
}
\author{
Jens Oehlschlägel
}
\keyword{classes}
\keyword{logic}
|