Module 2 Assignment: Does this Function work?

 For this assignment, I was tasked with reviewing a snippet of R code to determine if it could run properly:


assignment2 <- c(16, 18, 14, 22, 27, 17, 19, 17, 17, 22, 20, 22)
myMean <- function(assignment2) { return(sum(assignment2)/length(assignment2)) }
myMean(assignment2)


While this code does work properly (returns the average of the assignment 2 vector), using the name of the vector within the function isn't necessary, as said name still needs to be used when he function is called. Using a more simple variable like "x" for defining the function is much more understandable to those who wish to reuse said function.

myMean <- function(x) { return(sum(x)/length(x)) }


(GitHub here: https://github.com/Retrolovania/R_Programming/blob/main/Module%202.R)

Comments

Popular posts from this blog

Module 6: Our First Graph

LIS 4317 Final Project: R Chart showing Game Price changes over time

Final Project: DescribeR v1.0.0