An R vector is the most basic data structure in R: it is an ordered collection of elements that are all the same type (such as numeric, character, or logical). Vectors are fundamental to data analysis in R because R is built around vectorized operations, meaning functions are designed to work on entire vectors at once rather than one value at a time. This allows R to perform calculations, transformations, and comparisons efficiently and with very concise code. Datasets themselves are essentially collections of vectors (each column is a vector), so understanding vectors is key to working with data frames, manipulating variables, and performing statistical analysis. In short, vectors are the building blocks that make R powerful, fast, and expressive for data analysis.
Assignment #5
For Module #5, I practiced matrix operations in R and checked whether two matrices could be inverted. First, I created the matrices using the assignment instructions: A <- matrix(1:100, nrow = 10) and B <- matrix(1:1000, nrow = 10) . I used dim(A) and dim(B) to confirm their sizes. Matrix A is a 10×10 square matrix, while matrix B is a 10×100 matrix, which means B is not square. Next, I calculated the determinant of A using det(A) . The determinant came out to be 0 , which tells me A is singular . A singular matrix does not have an inverse, so when I attempted solve(A) R returned an error (I used tryCatch() to capture the error message without stopping my code). I also attempted solve(B) , but that also produced an error because non-square matrices do not have inverses . So the results were expected: A cannot be inverted because its determinant is 0, and B cannot be inverted because it is not square. After checking inverses, I explored additional matrix operations to ...
Comments
Post a Comment