Description Usage Arguments Details Value Examples
This function is the interface and starting point to read Kantar TV-Raw-Data
(sometimes called PIN-Data). The function collects parameters on how
rawdata shall be imported and later analyzed, much like the interface of
Instar Analytics. All parameters, together with more information about
the tv rawdata, is returned as a list id
. This list is input to most
functions of the tv
package.
1 2 3 4 5 6 7 8 9 | setup(day = "2013-01-01", to = 1, obs = c("ind", "hh")[1],
hh.calc = c("normal", "by channel")[1], guest = TRUE, dem = TRUE,
dem.var = NULL, dem.day = NULL, dem.uni = TRUE, dem.join = FALSE,
view = TRUE, act = c("live", "tsv", "recordedview", "teletext")[1:2],
plt = c("terA", "terD", "satA", "satD", "cabA", "cabD", "iptv", "web",
"unknown"), tsv.cat = c("tsv", "overnight", "none")[3],
tsv.ref = FALSE, ttv = TRUE, tmb = list(wholeday = c(start =
"02:00:00", end = "25:59:59")), prg = TRUE, prg.seq = c("gross",
"net")[2], prg.join = FALSE, path = NULL, import = FALSE)
|
day |
A character vector. Can also be of class 'Date' (POSIX). Specifies
the days to import. The only excepted format is the ISO standard format,
e.g.: |
to |
Either a (single) numeric or character value. Default
is |
obs |
Either 'ind' (default) or 'hh'. The level of observation, either
the data is on individuals level or aggregated to household level. If 'hh',
|
hh.calc |
Either |
guest |
|
dem |
|
dem.var |
Character vector specifiying the additional variables of the
demorgaphics file to be imported. By default |
dem.day |
For the |
dem.uni |
|
dem.join |
|
view |
|
act |
A character vector. Like in Instar Analytics possible values are
|
plt |
A character vector. Possible values are found here: id$lab$plt$name
Default is to use all. |
tsv.cat |
A character vector. Possible values are |
tsv.ref |
|
ttv |
|
tmb |
A list of time bands of the form: |
prg |
|
prg.seq |
Either |
prg.join |
|
path |
To specify ad hoc paths. |
import |
|
The default values provide the minimum on information for performance reason but enough to calculate standard estimates (facts). The default values are usually the same as the default in Instar Analytics. All parameters are optional. There are many parameters to specify the data import.
Dates in day
do not need to be continuous or in chronological order,
e.g loading weekends only is fine. Lowest possible value is '2013-01-01'
.
Highest possible value is yesterday's date, e.g.: Sys.Date()-1)
but depends
on what is found in the /data
directory in path
. Like in Instar
Analytics, Overnight +7 is only available after 8 days.
If some files specified to import are not found under /data, instead of breaking, the program runs with a warning listing all missing files.
A list named id
containing all nescessary information to
read the rawdata. id
is assigned to the global environment for
convenience while interactive programming. At the same time the function
returns the same list in the classical way, allowing assignment
(e.g.: id <- setup()
). The latter is nescessary to import the data
within a function call. See examples. If setup(import = TRUE)
the subfunction
import(id)
is called and consequently in addition the data.tables
dem,view,prog
are returned. Again, to the global environment. See
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 | # calculate standard facts for 10 days:
library(tv)
setup('2018-01-01', 10, dem.join = TRUE, import = TRUE)
calc(view)
# the same, for non-interactive programming and more educative:
id <- setup('2018-01-01', 10)
data <- import(id)
dem <- data$dem
view <- data$view
prog <- data$prog
join <- view[dem, on = c('day','pin')]
calc(join, by = 'day')
# what is meant by interactive programming?
?interactive
# speed up import, if not all of the 3 datsets (dem, view, prg) are needed:
setup('2018-01-01', dem = TRUE, view = FALSE, prg = FALSE) # only dem
# import more demografic variables:
id$file$dem$name # all available variables of the dem-files
setup('2018-01-01', dem = TRUE, dem.var = c('sg','age','sex'), import = TRUE)
# create variable "ageclass" based on variable "age":
dem.add(dem, 'ageclass')
# calculate facts by target group:
calc.uni(dem, target = c('day','sg','ageclass','sex'))
join <- view[dem, on = c('day','pin')]
res <- calc(join, by = c('day','sg','ageclass','sex'))
res
# switch between values and labels:
res[, 'sg' := id$lab$sg[res, on = 'sg', label]]
res[, 'ageclass' := id$lab$ageclass[res, on = 'ageclass', label]]
res[, 'sex' := id$lab$sex[, x := c('male','female')][res, on = 'sex', x]] # customize
# switch back to values:
res[, 'sg' := id$lab$sg[res, on = c(label='sg'), sg]]
res[, 'ageclass' := id$lab$ageclass[res, on = c(label='ageclass'), ageclass]]
res[, 'sex' := id$lab$sex[res, on = c(x = 'sex'), sex]]
# specify date, date range
setup('2018.12.31') # Error with message what date format is expected
setup('31-12-2018') # Error
setup('2018-12-31') # correct
A. date as a vector of dates
setup(day = '2018-01-01', import = TRUE)
setup(day = c('2017-01-02','2018-01-02','2019-01-01'), import = TRUE)
dem[, .N, k = day] # number of rows per day
B. date as a continuous sequence to a reference date
setup(day = '2018-01-01', to = 10, import = TRUE) # the 10 following days
setup(day = '2018-01-01', -3, import = TRUE) # the 3 previous days
C. date as a continuous sequence with start and end date
setup('2018-01-01', '2018-01-31', import = TRUE)
# add calendar variables "year" "month", "weekday", "weekend" etc.
dem.add(dem, 'calendar')
dem[, 'wend' := id$lab$wend[dem, on = 'wend', label]]
dem[, .N, k = .(day,wend)]
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.