diff --git a/.nojekyll b/.nojekyll index 029acbd..6fe3fe9 100644 --- a/.nojekyll +++ b/.nojekyll @@ -1 +1 @@ -72112e69 \ No newline at end of file +3a530297 \ No newline at end of file diff --git a/functions.html b/functions.html index 85a256b..6b8eabb 100644 --- a/functions.html +++ b/functions.html @@ -356,7 +356,7 @@ }; // Store cell data -globalThis.qwebrCellDetails = [{"code":"myFunction <- function(myArg1, myArg2){\n # Do something with myArg1 and myArg2\n # and the result of interest in an object\n # (e.g. vector, list or data frame)\n myResult <- myArg1 * myArg2\n \n # Return the result object\n return(myResult)\n}\n\nx <- 5\ny <- 10\nz <- myFunction(x,y)\nprint(z)","id":1,"options":{"editor-word-wrap":"true","out-width":"700px","dpi":72,"results":"markup","output":"true","message":"true","read-only":"false","fig-width":7,"classes":"","editor-quick-suggestions":"false","comment":"","editor-font-scale":"1","context":"interactive","warning":"true","fig-cap":"","fig-height":5,"autorun":"false","editor-max-height":"","label":"unnamed-chunk-1","out-height":""}},{"code":"# a,b is function's argument list\nmySum <- function(a, b){\n # the next two lines are the function's body\n c <- a + b\n return(c)\n}","id":2,"options":{"editor-word-wrap":"true","out-width":"700px","dpi":72,"results":"markup","output":"true","message":"true","read-only":"false","fig-width":7,"classes":"","editor-quick-suggestions":"false","comment":"","editor-font-scale":"1","context":"interactive","warning":"true","fig-cap":"","fig-height":5,"autorun":"false","editor-max-height":"","label":"unnamed-chunk-2","out-height":""}},{"code":"# This function has an empty argument list\ngreeting <- function(){\n # The function body contains only the next line. There is no return() statement.\n print(\"Greetings!\")\n}","id":3,"options":{"editor-word-wrap":"true","out-width":"700px","dpi":72,"results":"markup","output":"true","message":"true","read-only":"false","fig-width":7,"classes":"","editor-quick-suggestions":"false","comment":"","editor-font-scale":"1","context":"interactive","warning":"true","fig-cap":"","fig-height":5,"autorun":"false","editor-max-height":"","label":"unnamed-chunk-3","out-height":""}},{"code":"# This function takes a single argument, x, a numeric vector\nrunRegression <- function(dataset){\n # The body of this function performs linear regression\n # and returns the adjusted R-squared value.\n fit <- lm(y ~ x, data=dataset)\n fit.sum <- fit |> summary()\n return(fit.sum$adj.r.squared)\n}","id":4,"options":{"editor-word-wrap":"true","out-width":"700px","dpi":72,"results":"markup","output":"true","message":"true","read-only":"false","fig-width":7,"classes":"","editor-quick-suggestions":"false","comment":"","editor-font-scale":"1","context":"interactive","warning":"true","fig-cap":"","fig-height":5,"autorun":"false","editor-max-height":"","label":"unnamed-chunk-4","out-height":""}}]; +globalThis.qwebrCellDetails = [{"code":"myFunction <- function(myArg1, myArg2){\n # Do something with myArg1 and myArg2\n # and the result of interest in an object\n # (e.g. vector, list or data frame)\n myResult <- myArg1 * myArg2\n \n # Return the result object\n return(myResult)\n}\n\nx <- 5\ny <- 10\nz <- myFunction(x,y)\nprint(z)","id":1,"options":{"context":"interactive","out-height":"","results":"markup","dpi":72,"autorun":"false","output":"true","read-only":"false","editor-word-wrap":"true","warning":"true","classes":"","label":"unnamed-chunk-1","fig-height":5,"comment":"","out-width":"700px","fig-cap":"","editor-max-height":"","fig-width":7,"message":"true","editor-font-scale":"1","editor-quick-suggestions":"false"}},{"code":"# a,b is function's argument list\nmySum <- function(a, b){\n # the next two lines are the function's body\n c <- a + b\n return(c)\n}\n\n# Usage example:\nmySum(4,76)","id":2,"options":{"context":"interactive","out-height":"","results":"markup","dpi":72,"autorun":"false","output":"true","read-only":"false","editor-word-wrap":"true","warning":"true","classes":"","label":"unnamed-chunk-2","fig-height":5,"comment":"","out-width":"700px","fig-cap":"","editor-max-height":"","fig-width":7,"message":"true","editor-font-scale":"1","editor-quick-suggestions":"false"}},{"code":"# This function has an empty argument list\ngreeting <- function(){\n # The function body contains only the next line. There is no return() statement.\n print(\"Greetings!\") \n\n # Note: this function does not return an object or value.\n}\n\n# Usage example\ngreeting()","id":3,"options":{"context":"interactive","out-height":"","results":"markup","dpi":72,"autorun":"false","output":"true","read-only":"false","editor-word-wrap":"true","warning":"true","classes":"","label":"unnamed-chunk-3","fig-height":5,"comment":"","out-width":"700px","fig-cap":"","editor-max-height":"","fig-width":7,"message":"true","editor-font-scale":"1","editor-quick-suggestions":"false"}},{"code":"# This function takes a single argument, x, a numeric vector\nrunRegression <- function(dataset){\n # The body of this function performs linear regression\n # and returns the adjusted R-squared value.\n fit <- lm(y ~ x, data=dataset)\n fit.sum <- fit |> summary()\n return(fit.sum$adj.r.squared)\n}\n\n# Usage example\nmyDataframe <- data.frame(x = rnorm(10), y = rnorm(10)) # make a dataframe.\nrunRegression(myDataframe)","id":4,"options":{"context":"interactive","out-height":"","results":"markup","dpi":72,"autorun":"false","output":"true","read-only":"false","editor-word-wrap":"true","warning":"true","classes":"","label":"unnamed-chunk-4","fig-height":5,"comment":"","out-width":"700px","fig-cap":"","editor-max-height":"","fig-width":7,"message":"true","editor-font-scale":"1","editor-quick-suggestions":"false"}},{"code":"# This function takes no arguments\ngetMonths <- function(){\n monthNames <- c(\"January\", \"February\", \"March\", \"April\", \"May\", \"June\", \"July\", \"August\", \"September\", \"October\", \"November\", \"December\")\n return(monthNames)\n}\n\n# Usage example\ngetMonths()","id":5,"options":{"context":"interactive","out-height":"","results":"markup","dpi":72,"autorun":"false","output":"true","read-only":"false","editor-word-wrap":"true","warning":"true","classes":"","label":"unnamed-chunk-5","fig-height":5,"comment":"","out-width":"700px","fig-cap":"","editor-max-height":"","fig-width":7,"message":"true","editor-font-scale":"1","editor-quick-suggestions":"false"}},{"code":"# This function takes a single argument \ngreetPerson <- function(personName){\n message(\"Hello, \", personName, \"!\")\n # Note: This function does not return anything. \n}\n\n# Usage example\nperson <- \"John\"\ngreetPerson(person)","id":6,"options":{"context":"interactive","out-height":"","results":"markup","dpi":72,"autorun":"false","output":"true","read-only":"false","editor-word-wrap":"true","warning":"true","classes":"","label":"unnamed-chunk-6","fig-height":5,"comment":"","out-width":"700px","fig-cap":"","editor-max-height":"","fig-width":7,"message":"true","editor-font-scale":"1","editor-quick-suggestions":"false"}},{"code":"# This function takes two arguments\ncalcBMI <- function(height, weight){\n BMI <- weight / height^2\n return(BMI)\n}\n\n# Usage example\nweight <- 65\ncalcBMI(1.8, weight)","id":7,"options":{"context":"interactive","out-height":"","results":"markup","dpi":72,"autorun":"false","output":"true","read-only":"false","editor-word-wrap":"true","warning":"true","classes":"","label":"unnamed-chunk-7","fig-height":5,"comment":"","out-width":"700px","fig-cap":"","editor-max-height":"","fig-width":7,"message":"true","editor-font-scale":"1","editor-quick-suggestions":"false"}},{"code":"triple <- function(myNum){\n result <- myNum*3\n return(result)\n}\n\n# Usage Example: No name\nx <- 5\ntriple(x)\n\n# Usage Example: Named argument\nx <- 5\ntriple(myNum = x)","id":8,"options":{"context":"interactive","out-height":"","results":"markup","dpi":72,"autorun":"false","output":"true","read-only":"false","editor-word-wrap":"true","warning":"true","classes":"","label":"unnamed-chunk-8","fig-height":5,"comment":"","out-width":"700px","fig-cap":"","editor-max-height":"","fig-width":7,"message":"true","editor-font-scale":"1","editor-quick-suggestions":"false"}},{"code":"printFullName <- function(firstname, middlename, lastname){\n message(\"Full Name: \", firstname, \" \", middlename, \" \", lastname)\n # This function does not return anything.\n}\n\n# Usage Example: Normal order for arguments (no names)\nprintFullName(\"Jan\", \"Igor\", \"Hanssen\")\n\n# Usage Example: Rearranged order for arguments (names required)\nprintFullName(lastname=\"Hanssen\", firstname=\"Jan\", middlename=\"Igor\")\n\n# Usage Example: Incorrect output (without names)\nprintFullName(\"Hanssen\", \"Jan\", \"Igor\") # The computer is not psychic.","id":9,"options":{"context":"interactive","out-height":"","results":"markup","dpi":72,"autorun":"false","output":"true","read-only":"false","editor-word-wrap":"true","warning":"true","classes":"","label":"unnamed-chunk-9","fig-height":5,"comment":"","out-width":"700px","fig-cap":"","editor-max-height":"","fig-width":7,"message":"true","editor-font-scale":"1","editor-quick-suggestions":"false"}},{"code":"hoursToMinutes <- function(hours){\n return(hours*60)\n}\n\n# Usage Example: Without names\nhoursToMinutes(2)\n\n# Usage Example: With names\nhoursToMinutes(hours = 2)\n\n# Output is the same.","id":10,"options":{"context":"interactive","out-height":"","results":"markup","dpi":72,"autorun":"false","output":"true","read-only":"false","editor-word-wrap":"true","warning":"true","classes":"","label":"unnamed-chunk-10","fig-height":5,"comment":"","out-width":"700px","fig-cap":"","editor-max-height":"","fig-width":7,"message":"true","editor-font-scale":"1","editor-quick-suggestions":"false"}},{"code":"inchesToMeters <- function(inches){\n meters <- inches * 2.54 / 100\n return(meters)\n}\n\n# Usage Example: Without names\nx <- inchesToMeters(60)\n# This gives an error, because the meters object only exists inside the function.\nprint(meters)","id":11,"options":{"context":"interactive","out-height":"","results":"markup","dpi":72,"autorun":"false","output":"true","read-only":"false","editor-word-wrap":"true","warning":"true","classes":"","label":"unnamed-chunk-11","fig-height":5,"comment":"","out-width":"700px","fig-cap":"","editor-max-height":"","fig-width":7,"message":"true","editor-font-scale":"1","editor-quick-suggestions":"false"}},{"code":"# Calculate the cube of a number\nx <- 3\nx*x*x\n\n# Your function\ncubeNum <- function(x){\n # Put your code here.\n\n}\n\n# Use your function\n\ncubeNum(10)","id":12,"options":{"context":"interactive","out-height":"","results":"markup","dpi":72,"autorun":"false","output":"true","read-only":"false","editor-word-wrap":"true","warning":"true","classes":"","label":"unnamed-chunk-12","fig-height":5,"comment":"","out-width":"700px","fig-cap":"","editor-max-height":"","fig-width":7,"message":"true","editor-font-scale":"1","editor-quick-suggestions":"false"}},{"code":"# Your function\ncubeNum <- function(x){\n\n # Calculate the cube of a number\n x*x*x\n\n}\n\n# Use your function\n\ncubeNum(10)","id":13,"options":{"context":"interactive","out-height":"","results":"markup","dpi":72,"autorun":"false","output":"true","read-only":"false","editor-word-wrap":"true","warning":"true","classes":"","label":"unnamed-chunk-13","fig-height":5,"comment":"","out-width":"700px","fig-cap":"","editor-max-height":"","fig-width":7,"message":"true","editor-font-scale":"1","editor-quick-suggestions":"false"}}];