Module # 2 Introduction to basic R functions and Data Structures

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

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


result <- myMean(assignment2)

result

[1] 19.41667 


Explanation: 

The 'myMean' function takes a vector of numbers as input and calculates the mean by dividing the sum of the numbers by the length of the vector. 

The function works correctly because it follows the formula for calculating the mean, which is the sum of all values divided by the number of values. 

Comments

Popular posts from this blog

Final Project [LIS4317]

Module # 7 assignment (Visual Analytics)

Module # 8 Input/Output, string manipulation and plyr package