Posts

Showing posts from January, 2026
Image
 For this assignment, I worked on importing data into RStudio and practicing basic R programming by testing and debugging a user-defined function. The goal was to understand how R functions handle variables and why correct naming is important. I started by creating a numeric vector in RStudio called assignment2 , which contains twelve values. This vector was used as the input for testing the function. Next, I tested the provided  myMean  function by running  myMean(assignment2)  in the R console. Instead of returning a number, R produced an error. The function failed because it referenced variables that did not exist. Although the function argument was named assignment2 , the function body used the names assignment and someData . Since R functions can only access variables passed into the function or defined within it, this mismatch caused the error. To fix the problem, I updated the function so that it consistently used the argument name assignment2 when c...
  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.