seq.count: Count the number of occurences of a given value in a channel

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

Description

The seq.count function counts the number of occurences of a given value in a channel. Currently a channel is represented as a set of column names of a data.frame and the corresponding data.frame.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
seq.count(
  x,
  value,
  sequence = names(x),
  origin,
  window.start = 0,
  window.end,
  translate = NULL,
  verbose = FALSE,
  quiet = FALSE
)

Arguments

x

a data.frame.

value

a numeric of character of length 1, corresponding to the value you want to count.

sequence

a character. The columns of x in which you want to count.

origin

a character. The column from which you want to start to count.

window.start

a numeric. Allow to translate the start. Positive or negative values are accepted. Default is 0, meaning we start at the origin.

window.end

a numeric. Specify how many of column from the origin you want to take. For example, if you set the parameter to 1, you will count on only the column origin. And if you set the parameter to 10, you will use the column origin and the 9 following.

translate

a numeric or character of lenght 1. If a numeric is used, all the window will be translated according to the value provided: the same translation is applied for each individuals. If a character is used, the function will look for a column with the corresponding name and will translate the window of each row according to its value on the variable used for translating. Furthermore, the argument can be named with 'left', meaning that the translation will be performed negatively (on the left) instead of positively (on the right, the default).

verbose

a logical. See the Section Value.

quiet

a numeric. If TRUE information messages won't be displayed. Default is FALSE.

Details

Please take care that if you use a variable for translating windows for each individual, and this variable contains NA, the corresponding rows will be removed. In this case you will be alerted by a warning.

Value

A data.frame. If verbose is FALSE the data.frame contains only one columns, named COUNT, corresponding to the count for each individual. If verbose is TRUE the data.frame will also contains columns helping to control how the count was performed: START, STOP, RANGE, TRANSLATE and the columns corresponding to the channel.

Author(s)

Emmanuel Rousseaux

See Also

find.value.fun, findlast.

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
 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
# data.frame example
data.ex <- data.frame(
  "id" = 1:7,
  "age.2010" =  c(5,3,0,1,4,NA,30),
  "vuln.2000" = c(0,1,1,0,NA,1,1),
  "vuln.2001" = c(0,0,1,0,NA,1,1),
  "vuln.2002" = c(0,1,0,1,NA,0,0),
  "vuln.2003" = c(0,0,0,1,NA,1,1),
  "vuln.2004" = c(0,NA,1,1,NA,1,1),
  "vuln.2005" = c(0,0,1,0,NA,0,1),
  "vuln.2006" = c(0,0,1,0,NA,0,1),
  "vuln.2007" = c(0,0,0,1,NA,1,1),
  "vuln.2008" = c(0,0,1,1,NA,1,0),
  "vuln.2009" = c(0,0,0,1,NA,1,0),
  "vuln.2010" = c(0,0,1,1,NA,1,1)
)
data.ex

#### Example 0
# We count only in the year 2006
count0 <- seq.count(
  x = data.ex,
  value = 1,
  sequence = c("vuln.2000","vuln.2001","vuln.2002","vuln.2003","vuln.2004","vuln.2005","vuln.2006","vuln.2007","vuln.2008","vuln.2009","vuln.2010"),
  origin = "vuln.2006",
  window.end = 1 # we take only 1 measure
)
count0

# Same example with the mode 'verbose' on
count0 <- seq.count(
  x = data.ex,
  value = 1,
  sequence = c("vuln.2000","vuln.2001","vuln.2002","vuln.2003","vuln.2004","vuln.2005","vuln.2006","vuln.2007","vuln.2008","vuln.2009","vuln.2010"),
  origin = "vuln.2006",
  window.end = 1, # we take only 1 measure
  verbose = TRUE
)
count0


#### Example 1
# We count between 2006 (included) and 2008 (included)
count1 <- seq.count(
  x = data.ex,
  value = 1,
  sequence = c("vuln.2000","vuln.2001","vuln.2002","vuln.2003","vuln.2004","vuln.2005","vuln.2006","vuln.2007","vuln.2008","vuln.2009","vuln.2010"),
  origin = "vuln.2006",
  window.end = 3
)
count1

# Same example with the mode 'verbose' on
count1 <- seq.count(
  x = data.ex,
  value = 1,
  sequence = c("vuln.2000","vuln.2001","vuln.2002","vuln.2003","vuln.2004","vuln.2005","vuln.2006","vuln.2007","vuln.2008","vuln.2009","vuln.2010"),
  origin = "vuln.2006",
  window.end = 3,
  verbose = TRUE
)
count1


#### Example 2
# For each individual we count occurences of '1' when there where between 0 and 2 years (included)
count2 <- seq.count(
  x = data.ex,
  value = 1,
  sequence = c("vuln.2000","vuln.2001","vuln.2002","vuln.2003","vuln.2004","vuln.2005","vuln.2006","vuln.2007","vuln.2008","vuln.2009","vuln.2010"),
  origin = "vuln.2010", # as we have the age in 2010, we use vuln.2010 as origin
  window.end = 3, # 0, 1 and 2 years
  translate = c('left' = 'age.2010')
)
count2

# Same example with the mode 'verbose' on
count2 <- seq.count(
  x = data.ex,
  value = 1,
  sequence = c("vuln.2000","vuln.2001","vuln.2002","vuln.2003","vuln.2004","vuln.2005","vuln.2006","vuln.2007","vuln.2008","vuln.2009","vuln.2010"),
  origin = "vuln.2010", # as we have the age in 2010, we use vuln.2010 as origin
  window.end = 3, # 0, 1 and 2 years
  translate = c('left' = 'age.2010'),
  verbose = TRUE
)
count2


#### Example 3
# For each individual we count occurences of '1' when there were 2 years
count3 <- seq.count(
  x = data.ex,
  value = 1,
  sequence = c("vuln.2000","vuln.2001","vuln.2002","vuln.2003","vuln.2004","vuln.2005","vuln.2006","vuln.2007","vuln.2008","vuln.2009","vuln.2010"),
  origin = "vuln.2010",
  window.start = 2, # we start two values after origin: corresponding to 2 years old
  window.end = 3, # and we stop three values after origin: we get only the value at 2 years
  translate = c('left' = 'age.2010'),
  verbose = TRUE
)
count3

#### Example 4
# For each individual we count occurences of '1' when there were betweeb 2 years and 5 years
count4 <- seq.count(
  x = data.ex,
  value = 1,
  sequence = c("vuln.2000","vuln.2001","vuln.2002","vuln.2003","vuln.2004","vuln.2005","vuln.2006","vuln.2007","vuln.2008","vuln.2009","vuln.2010"),
  origin = "vuln.2010",
  window.start = 2, # we start two values after origin: corresponding to 2 years old
  window.end = 6,  # and we stop six values after origin: we get the count for the range [2-5]
  translate = c('left' = 'age.2010'),
  verbose = TRUE
)
count4

Rsocialdata0 documentation built on May 2, 2019, 5:55 p.m.