prepend_values: Prepend values/variable names to value/variable labels

Description Usage Arguments Value Examples

Description

These functions add values/variable names as prefixes to value/variable labels. Functions which start with tab_ intended for usage inside table creation sequences. See examples and tables. It is recommended to use tab_prepend_* at the start of sequence of tables creation. If you use it in the middle of the sequence then previous statements will not be affected.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11

Arguments

x

vector/data.frame. prepend_names can be applied only to data.frames.

data

data.frame/intermediate result of tables construction. See tables.

Value

original object with prepended names/values to labels

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
data(mtcars)
mtcars = apply_labels(mtcars,
                      mpg = "Miles/(US) gallon",
                      cyl = "Number of cylinders",
                      disp = "Displacement (cu.in.)",
                      hp = "Gross horsepower",
                      drat = "Rear axle ratio",
                      wt = "Weight (lb/1000)",
                      qsec = "1/4 mile time",
                      vs = "Engine",
                      vs = c("V-engine" = 0,
                             "Straight engine" = 1),
                      am = "Transmission",
                      am = c("Automatic" = 0,
                             "Manual"=1),
                      gear = "Number of forward gears",
                      carb = "Number of carburetors"
)

# prepend names and 'cro_cpct'
mtcars %>% 
       prepend_names %>% 
       calculate(
              cro_cpct(list(cyl, gear), list(total(), vs, am))
           )
     
# prepend values to value labels                 
mtcars %>% 
   tab_prepend_values %>% 
   tab_cols(total(), vs, am) %>% 
   tab_cells(cyl, gear) %>% 
   tab_stat_cpct() %>% 
   tab_pivot()

# prepend names and labels
mtcars %>% 
   tab_prepend_all %>% 
   tab_cols(total(), vs, am) %>% 
   tab_cells(cyl, gear) %>% 
   tab_stat_cpct() %>% 
   tab_pivot() 
   
# variable in rows without prefixes
mtcars %>% 
   tab_cells(cyl, gear) %>% 
   tab_prepend_all %>% 
   tab_cols(total(), vs, am) %>% 
   tab_stat_cpct() %>% 
   tab_pivot()   

gdemin/expss documentation built on May 16, 2019, 11:14 p.m.