These functions adapt dplyr verbs to the factors of a tbl_ord.

The raw verbs are not defined for tbl_ords; instead, each verb has two analogues, corresponding to the two matrix factors. They each rely on a common workhorse function, which takes the composition of the dplyr verb with annotation_*, applied to the factor, removes any variables corresponding to coordinates or already annotated, and only then assigns it as the new "*_annotation" attribute of .data (see annotation). Note that these functions are not generics and so cannot be extended to other classes.

pull_factor(.data, var = -1, .matrix)

pull_rows(.data, var = -1)

pull_cols(.data, var = -1)

rename_rows(.data, ...)

rename_cols(.data, ...)

select_rows(.data, ...)

select_cols(.data, ...)

mutate_rows(.data, ...)

mutate_cols(.data, ...)

transmute_rows(.data, ...)

transmute_cols(.data, ...)

cbind_rows(.data, ..., elements = "all")

cbind_cols(.data, ..., elements = "all")

left_join_rows(.data, ...)

left_join_cols(.data, ...)

Arguments

.data

An object of class 'tbl_ord'.

var

A variable specified as in dplyr::pull().

.matrix

A character string partially matched (lowercase) to several indicators for one or both matrices in a matrix decomposition used for ordination. The standard values are "rows", "cols", and "dims" (for both).

...

Comma-separated unquoted expressions as in, e.g., dplyr::select().

elements

Character vector; which elements of each factor for which to render graphical elements. One of "all" (the default), "active", or any supplementary element type defined by the specific class methods (e.g. "score" for 'factanal', 'lda_ord', and 'cancord_ord' and "intraset" and "interset" for 'cancor_ord').

Value

A tbl_ord; the wrapped model is unchanged.

Examples

# illustrative ordination: LDA of iris data
(iris_lda <- ordinate(iris, cols = 1:4, lda_ord, grouping = iris$Species))
#> Warning: Could not locate data used to fit 'x'.
#> # A tbl_ord of class 'lda_ord': (153 x 2) x (4 x 2)'
#> # 2 coordinates: LD1 and LD2
#> # 
#> # Rows (principal): [ 153 x 2 | 5 ]
#>     LD1    LD2 |   name        prior counts .element
#>                |   <chr>       <dbl>  <int> <chr>   
#> 1  7.61  0.215 | 1 setosa      0.333     50 active  
#> 2 -1.83 -0.728 | 2 versicolor  0.333     50 active  
#> 3 -5.78  0.513 | 3 virginica   0.333     50 active  
#> 4 NA    NA     | 4 NA         NA         NA score   
#> 5 NA    NA     | 5 NA         NA         NA score   
#> # … with 148 more rows, and 1 more
#> #   variable: Species <fct>
#> # 
#> # Columns (standard): [ 4 x 2 | 2 ]
#>      LD1     LD2 |   name         .element
#>                  |   <chr>        <chr>   
#> 1  0.829  0.0241 | 1 Sepal.Length active  
#> 2  1.53   2.16   | 2 Sepal.Width  active  
#> 3 -2.20  -0.932  | 3 Petal.Length active  
#> 4 -2.81   2.84   | 4 Petal.Width  active  

# extract a coordinate or annotation
head(pull_rows(iris_lda, Species))
#> [1] <NA>   <NA>   <NA>   setosa setosa setosa
#> Levels: setosa versicolor virginica
pull_cols(iris_lda, LD2)
#> [1]  0.02410215  2.16452123 -0.93192121  2.83918785

# rename an annotation
rename_cols(iris_lda, species = name)
#> # A tbl_ord of class 'lda_ord': (153 x 2) x (4 x 2)'
#> # 2 coordinates: LD1 and LD2
#> # 
#> # Rows (principal): [ 153 x 2 | 5 ]
#>     LD1    LD2 |   name        prior counts .element
#>                |   <chr>       <dbl>  <int> <chr>   
#> 1  7.61  0.215 | 1 setosa      0.333     50 active  
#> 2 -1.83 -0.728 | 2 versicolor  0.333     50 active  
#> 3 -5.78  0.513 | 3 virginica   0.333     50 active  
#> 4 NA    NA     | 4 NA         NA         NA score   
#> 5 NA    NA     | 5 NA         NA         NA score   
#> # … with 148 more rows, and 1 more
#> #   variable: Species <fct>
#> # 
#> # Columns (standard): [ 4 x 2 | 2 ]
#>      LD1     LD2 |   species      .element
#>                  |   <chr>        <chr>   
#> 1  0.829  0.0241 | 1 Sepal.Length active  
#> 2  1.53   2.16   | 2 Sepal.Width  active  
#> 3 -2.20  -0.932  | 3 Petal.Length active  
#> 4 -2.81   2.84   | 4 Petal.Width  active  

# select annotations
select_rows(iris_lda, species = name, .element)
#> # A tbl_ord of class 'lda_ord': (153 x 2) x (4 x 2)'
#> # 2 coordinates: LD1 and LD2
#> # 
#> # Rows (principal): [ 153 x 2 | 2 ]
#>     LD1    LD2 |   species    .element
#>                |   <chr>      <chr>   
#> 1  7.61  0.215 | 1 setosa     active  
#> 2 -1.83 -0.728 | 2 versicolor active  
#> 3 -5.78  0.513 | 3 virginica  active  
#> 4 NA    NA     | 4 NA         score   
#> 5 NA    NA     | 5 NA         score   
#> # … with 148 more rows
#> # 
#> # Columns (standard): [ 4 x 2 | 2 ]
#>      LD1     LD2 |   name         .element
#>                  |   <chr>        <chr>   
#> 1  0.829  0.0241 | 1 Sepal.Length active  
#> 2  1.53   2.16   | 2 Sepal.Width  active  
#> 3 -2.20  -0.932  | 3 Petal.Length active  
#> 4 -2.81   2.84   | 4 Petal.Width  active  

# create, modify, and delete annotations
mutate_cols(iris_lda, vec.length = sqrt(LD1^2 + LD2^2))
#> # A tbl_ord of class 'lda_ord': (153 x 2) x (4 x 2)'
#> # 2 coordinates: LD1 and LD2
#> # 
#> # Rows (principal): [ 153 x 2 | 5 ]
#>     LD1    LD2 |   name        prior counts .element
#>                |   <chr>       <dbl>  <int> <chr>   
#> 1  7.61  0.215 | 1 setosa      0.333     50 active  
#> 2 -1.83 -0.728 | 2 versicolor  0.333     50 active  
#> 3 -5.78  0.513 | 3 virginica   0.333     50 active  
#> 4 NA    NA     | 4 NA         NA         NA score   
#> 5 NA    NA     | 5 NA         NA         NA score   
#> # … with 148 more rows, and 1 more
#> #   variable: Species <fct>
#> # 
#> # Columns (standard): [ 4 x 2 | 3 ]
#>      LD1     LD2 |   name         .element vec.length
#>                  |   <chr>        <chr>         <dbl>
#> 1  0.829  0.0241 | 1 Sepal.Length active        0.830
#> 2  1.53   2.16   | 2 Sepal.Width  active        2.65 
#> 3 -2.20  -0.932  | 3 Petal.Length active        2.39 
#> 4 -2.81   2.84   | 4 Petal.Width  active        3.99 
transmute_cols(iris_lda, vec.length = sqrt(LD1^2 + LD2^2))
#> # A tbl_ord of class 'lda_ord': (153 x 2) x (4 x 2)'
#> # 2 coordinates: LD1 and LD2
#> # 
#> # Rows (principal): [ 153 x 2 | 5 ]
#>     LD1    LD2 |   name        prior counts .element
#>                |   <chr>       <dbl>  <int> <chr>   
#> 1  7.61  0.215 | 1 setosa      0.333     50 active  
#> 2 -1.83 -0.728 | 2 versicolor  0.333     50 active  
#> 3 -5.78  0.513 | 3 virginica   0.333     50 active  
#> 4 NA    NA     | 4 NA         NA         NA score   
#> 5 NA    NA     | 5 NA         NA         NA score   
#> # … with 148 more rows, and 1 more
#> #   variable: Species <fct>
#> # 
#> # Columns (standard): [ 4 x 2 | 1 ]
#>      LD1     LD2 |   vec.length
#>                  |        <dbl>
#> 1  0.829  0.0241 | 1      0.830
#> 2  1.53   2.16   | 2      2.65 
#> 3 -2.20  -0.932  | 3      2.39 
#> 4 -2.81   2.84   | 4      3.99 

# bind data frames of annotations
iris_medians <-
  stats::aggregate(iris[, 1:4], median, by = iris[, 5, drop = FALSE])
iris_lda %>%
  # retain '.element' in order to match by `elements`
  select_rows(.element) %>%
  cbind_rows(iris_medians, elements = "active")
#> # A tbl_ord of class 'lda_ord': (153 x 2) x (4 x 2)'
#> # 2 coordinates: LD1 and LD2
#> # 
#> # Rows (principal): [ 153 x 2 | 6 ]
#>     LD1    LD2 |   .element Species   Sepal…¹ Sepal…²
#>                |   <chr>    <fct>       <dbl>   <dbl>
#> 1  7.61  0.215 | 1 active   setosa        5       3.4
#> 2 -1.83 -0.728 | 2 active   versicol…     5.9     2.8
#> 3 -5.78  0.513 | 3 active   virginica     6.5     3  
#> 4 NA    NA     | 4 score    NA           NA      NA  
#> 5 NA    NA     | 5 score    NA           NA      NA  
#> # … with 148 more rows, 2 more
#> #   variables: Petal.Length <dbl>,
#> #   Petal.Width <dbl>, and
#> #   abbreviated variable names
#> #   ¹​Sepal.Length, ²​Sepal.Width
#> # 
#> # Columns (standard): [ 4 x 2 | 2 ]
#>      LD1     LD2 |   name         .element
#>                  |   <chr>        <chr>   
#> 1  0.829  0.0241 | 1 Sepal.Length active  
#> 2  1.53   2.16   | 2 Sepal.Width  active  
#> 3 -2.20  -0.932  | 3 Petal.Length active  
#> 4 -2.81   2.84   | 4 Petal.Width  active