length.bit: Getting and setting length of bit, bitwhich and ri objects

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/bit.R

Description

Query the number of bits in a bit vector or change the number of bits in a bit vector.
Query the number of bits in a bitwhich vector or change the number of bits in a bit vector.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
## S3 method for class 'ri'
length(x)
## S3 method for class 'bit'
length(x)
## S3 method for class 'bitwhich'
length(x)
## S3 replacement method for class 'bit'
length(x) <- value
## S3 replacement method for class 'bitwhich'
length(x) <- value

Arguments

x

a bit, bitwhich or ri object

value

the new number of bits

Details

NOTE that the length does NOT reflect the number of selected (TRUE) bits, it reflects the sum of both, TRUE and FALSE bits. Increasing the length of a bit object will set new bits to FALSE. The behaviour of increasing the length of a bitwhich object is different and depends on the content of the object:

Decreasing the length of bit or bitwhich removes any previous information about the status bits above the new length.

Value

the length A bit vector with the new length

Author(s)

Jens Oehlschl<c3><a4>gel

See Also

length, sum, poslength, maxindex

Examples

 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
  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)

OHDSI/bit documentation built on May 9, 2017, 3:30 p.m.