drop_empty_rows: Drop empty (with all NA's) rows/columns from data.frame/table

Description Usage Arguments Value Examples

View source: R/drop_empty.R

Description

By default tables produced by functions tables, cro, cro_fun and cro_fun_df are created with all possible value labels. If values for this labels are absent in variable there are NA's in rows and columns. drop_empty_rows/drop_empty_columns are intended to remove these empty rows/columns. drop_r and drop_c are the same functions with shorter names. drop_rc drops rows and columns simultaneously.

Usage

1
2
3
4
5
6
7
8
9
drop_empty_rows(x, excluded_rows = NULL, excluded_columns = NULL)

drop_empty_columns(x, excluded_rows = NULL, excluded_columns = NULL)

drop_r(x, excluded_rows = NULL, excluded_columns = NULL)

drop_c(x, excluded_rows = NULL, excluded_columns = NULL)

drop_rc(x)

Arguments

x

data.frame/etable(result of cro and etc.)

excluded_rows

character/logical/numeric rows which won't be dropped and in which NAs won't be counted. If it is characters then they will be considered as pattern/vector of patterns. Patterns will be matched with Perl-style regular expression with values in the first column of x (see grep, perl = TRUE argument). Rows which have such patterns will be excluded. By default for class 'etable' pattern is "#" because "#" marks totals in the result of cro.

excluded_columns

logical/numeric/characters columns which won't be dropped and in which NAs won't be counted. By default for class 'etable' it is first column - column with labels in table.

Value

data.frame with removed rows/columns

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
data(mtcars)
mtcars = apply_labels(mtcars,
            vs = "Engine",
            vs = num_lab("
                      0 V-engine 
                      1 Straight engine
                      9 Other
                      "),
            am = "Transmission",
            am = num_lab("
                     0 Automatic 
                     1 Manual
                     9 Other
                     ")
         )
with_empty = calculate(mtcars, cro(am, vs))

drop_empty_rows(with_empty)
drop_empty_columns(with_empty)
drop_rc(with_empty)
                        

Example output

Use 'expss_output_rnotebook()' to display tables inside R Notebooks.
 To return to the console output, use 'expss_output_default()'.

                                                                     
 |              |              |   Engine |                 |       |
 |              |              | V-engine | Straight engine | Other |
 | ------------ | ------------ | -------- | --------------- | ----- |
 | Transmission |    Automatic |       12 |               7 |       |
 |              |       Manual |        6 |               7 |       |
 |              | #Total cases |       18 |              14 |       |
                                                             
 |              |              |   Engine |                 |
 |              |              | V-engine | Straight engine |
 | ------------ | ------------ | -------- | --------------- |
 | Transmission |    Automatic |       12 |               7 |
 |              |       Manual |        6 |               7 |
 |              |        Other |          |                 |
 |              | #Total cases |       18 |              14 |
                                                             
 |              |              |   Engine |                 |
 |              |              | V-engine | Straight engine |
 | ------------ | ------------ | -------- | --------------- |
 | Transmission |    Automatic |       12 |               7 |
 |              |       Manual |        6 |               7 |
 |              | #Total cases |       18 |              14 |

expss documentation built on Jan. 8, 2021, 5:38 p.m.