Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

pull_triangle

Pull Lower and Upper Triangular Part of a Matrix


Description

Returns the lower or the upper triangular part of a (correlation) matrix.

Usage

pull_triangle(x, triangle = c("lower", "upper"), diagonal = FALSE)

pull_upper_triangle(x, diagonal = FALSE)

pull_lower_triangle(x, diagonal = FALSE)

Arguments

x

a (correlation) matrix

triangle

the triangle to pull. Allowed values are one of "upper" and "lower".

diagonal

logical. Default is FALSE. If TRUE, the matrix diagonal is included.

Value

an object of class cor_mat_tri, which is a data frame

Functions

  • pull_triangle: returns either the lower or upper triangular part of a matrix.

  • pull_upper_triangle: returns an object of class upper_tri, which is a data frame containing the upper triangular part of a matrix.

  • pull_lower_triangle: returns an object of class lower_tri, which is a data frame containing the lower triangular part of a matrix.

See Also

Examples

# Data preparation
#::::::::::::::::::::::::::::::::::::::::::
mydata <- mtcars %>%
  select(mpg, disp, hp, drat, wt, qsec)
head(mydata, 3)

# Compute correlation matrix and pull triangles
#::::::::::::::::::::::::::::::::::::::::::
# Correlation matrix
cor.mat <- cor_mat(mydata)
cor.mat

# Pull lower triangular part
cor.mat %>% pull_lower_triangle()

# Pull upper triangular part
cor.mat %>% pull_upper_triangle()

rstatix

Pipe-Friendly Framework for Basic Statistical Tests

v0.7.0
GPL-2
Authors
Alboukadel Kassambara [aut, cre]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.