Monday, January 23, 2023

 In Assignment 2, we were presented with the prompt:

assignment2 <- c(161814222717191717222022)
>
myMean <- function(assignment2) { return(sum(assignment2)/length(assignment2)) }
> YOUR turn...


In analyzing this R code, after reading the article "Writing Functions Using R" it was apparent that the intended purpose of the function "myMean" was to return the mean value of the sequence "assignment2" by dividing the sum of the sequence by the length of the sequence.  As written, the code did nothing.  The expression was correctly formatted, but I needed to replace line 3 (>YOUR turn...) to get the code to return a value.  I chose to enter 

"> myMean(assignment2)" 

to apply the function to the object "assignment2".  When I did so, R returned [1] 19.25, which is the mean of the sequence.  It worked!


I am having a terrible time understanding how to link RStudio to GitHub.  I'm also uncertain if I should be using the Project window or the console window in RStudio to create and test my code.  It seems as though the project window is necessary for versioning.  If that is the case, why would I use the console window?  I'll figure this out eventually.


No comments: