RStudio Results:

Using the given dataset (I included the 19 that was in the instructions, but was not in the vector listed), I created the vector “assignment2.”

Since this vector is numeric, I can use mathematical functions in R.

I created the function “myMean” using the given instructions: myMean -> function(assignment2) {return(sum(assignment2)/length(assignment2))}

-> sum(assignment2) adds up all the values in the vector.

-> length(assignment2) counts the amount of values in the vector.

-> the “/” divides the values.

Using the given vector and the function “myMean” I found the mean of the vector to be 18.7. To conclude, the vector stores a dataset of numbers, and the function I created calculated the mean of that dataset. This assignment helped me get a introduction to understand vectors and creating functions in R.

Posted in

Leave a comment

Design a site like this with WordPress.com
Get started