Monday, August 28, 2023

LIS4273 Module 2 Assignment (New)

For this assignment, I will evaluate the function myMean and the variable assignment which contains a vector of numeric values. Due to some inconsistencies between the Module 2 assignment text and Module 2 example code, I will evaluate the code described in the assignment text as well as the example code and their associated outputs.

Assignment text input:

# A vector of numeric values assigned to assignment

assignment <- c(6, 18, 14, 22, 27, 17, 19, 22, 20, 22)

myMean <- function(assignment2){

  return(sum(assignment2) / length(assignment2))

}

Output:

Assignment example code input:

# Missing the value 19 from the vector and called assignment2 rather than assignment

 assignment2 <- c(6, 18, 14, 22, 27, 17, 22, 20, 22)

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

Output:

To describe what the function assignment2 does, we can see that it is an argument passed through the function. When we call the myMean function and insert the variable assignment or assignment2, it returns the simple mean of the chosen vector variable. The myMean function takes in a vector as input, and returns the sum of the vector values divided by the length of the vector.

Below are the following outputs of assignment text and assignment example code if we were to call the function and insert a variable to perform a calculation. 

Assignment text input:

myMean(assignment)

Output:

Assignment example code input:

myMean(assignment2)

Output:

As you can see, the outputs vary because the assignment vector contains the value 19 and holds 10 values as compared to the assignment2 vector containing only 9 values and is missing the value 19.

~ Katie 

No comments:

Post a Comment

LIS 4370 R Programming - sentimentTextAnalyzer2 Final Project

For this class's major final project, I set out to make the process of analyzing textual files and URL links for sentiment insights much...