Decomposition of Matrix Using qr() Function in R (Example Code)

This post demonstrates how to apply the qr() function in the R programming language.

Creating Exemplifying Data

set.seed(934785313)                    # Set seed
example_matrix <- matrix(runif(12),    # Construct matrix
                         ncol = 3)
example_matrix
#           [,1]      [,2]       [,3]
# [1,] 0.1340010 0.2110756 0.09286403
# [2,] 0.1848682 0.9196782 0.80487402
# [3,] 0.4348933 0.7077068 0.28186853
# [4,] 0.5300819 0.8499086 0.32658063
example_vector <- 11:14                # Construct vector
example_vector
# [1] 11 12 13 14

Example: How to Apply qr() Function to Decompose Matrix Object

solve(qr(example_matrix),              # QR Decomposition of Matrix
      example_vector)
# [1]  609.4401 -562.4200  517.5730

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed

Menu
Top