From 1985158194bc609ebfbde446e31b608414e46318 Mon Sep 17 00:00:00 2001
From: Alex Strashny First, let’s review what I call “advanced variable editing”. Some examples include [var_collapse()] and [var_cut()]. Occasionally, you might need to do advanced variable editing.
-Here’s how: Every survey object has an element called
- This is a data frame where the survey’s variables are
-located Keep in mind that every survey object has an element called
+ For an example of this, see
@@ -490,8 +492,8 @@ Advanced variable editing
-
+surveytable
provides a number of functions to create
-or modify survey variables.variables
surveytable
provides a number of functions to create or
+modify survey variables.var_collapse()
and
+var_cut()
.variables
. This is a data frame where the survey’s
+variables are located.
variables
data frame
(which is part of the survey object).set_survey()
again. Any time you modify the
-variables
data frame, call set_survey()
.set_survey()
again. Any time you
+modify the variables
data frame, call
+set_survey()
.Data flowreadRDS().
@@ -500,7 +502,7 @@
Data flowsaveRDS(). Normally, you
probably don’t want to do this. Normally, the survey file
@@ -509,13 +511,13 @@
Data flowvar_cut() or
var_collapse()
) modify (3). Since (3) is what
-surveytable
works with and tabulates, you can call
-var_collapse()
, and then you can call tab()
.
-You don’t need to do anything extra in between.
surveytable
works with and tabulates, you can use
+var_collapse()
, and then immediately use
+tab()
. You don’t need to do anything extra in between.
If you are modifying the variables
data frame directly,
-you are actually modifying (2). After you modify (2), you need to copy
-it over to (3), so that surveytable
can use it. You do that
-by calling set_survey()
.
surveytable
can use it. You do that by calling
+set_survey()
.
Thus, any time you modify variables
yourself, call
set_survey()
. You modify (2), then copy (2) -> (3) by
calling set_survey()
.
To create HTML or LaTeX tables from an R Markdown notebook or a
-Quarto document, add the results='asis'
argument to your
+Quarto document, add the results='asis'
argument to the
code chunk, like so:
The above should produce the following: