From 3d0368908643a85539c03b8274dcaaef2d2d1252 Mon Sep 17 00:00:00 2001 From: Natalie Elphick Date: Fri, 19 Jan 2024 11:44:09 -0800 Subject: [PATCH] Add more polls and fix some typos --- docs/Intro_to_R_data_analysis_part_1.html | 119 +++++++++++++----- docs/Intro_to_R_data_analysis_part_2.html | 2 +- .../Intro_to_R_data_analysis_part_1.Rmd | 70 ++++++++++- 3 files changed, 150 insertions(+), 41 deletions(-) diff --git a/docs/Intro_to_R_data_analysis_part_1.html b/docs/Intro_to_R_data_analysis_part_1.html index 3a93540..b238c98 100644 --- a/docs/Intro_to_R_data_analysis_part_1.html +++ b/docs/Intro_to_R_data_analysis_part_1.html @@ -2583,9 +2583,9 @@ Senior Statistician

What is your level of experience with coding/data analysis?

    -
  1. I am fluent in another data analysis programming language (Python, -Matlab etc.)
  2. -
  3. I am use Excel to do linear regression
  4. +
  5. I know another data analysis programming language (Python, Matlab +etc.)
  6. +
  7. I can use Excel to do linear regression
  8. I know some R
  9. All of the above
  10. None of the above
  11. @@ -2772,7 +2772,7 @@ one style of names -
    add_dog <- function(dog_to_add,
    -                    input_vector) {
    -  if (dog_to_add %in% input_vector) {
    -    
    -    message("Already contains this dog")
    -    
    -  } else {
    -    
    -    output <- c(dog_to_add, input_vector)
    -    return(output)
    -    
    -  }
    -}
    +
    add_dog <- function(dog_to_add,
    +                    input_vector) {
    +  if (dog_to_add %in% input_vector) {
    +    
    +    message("Already contains this dog")
    +    
    +  } else {
    +    
    +    output <- c(dog_to_add, input_vector)
    +    return(output)
    +    
    +  }
    +}

    Example

    -
    add_dog(dog_to_add = "Akita",
    -        input_vector = dog_breeds)
    -
    ## Already contains this dog
    -
    add_dog(dog_to_add = "German Shepard",
    +
    add_dog(dog_to_add = "Akita",
             input_vector = dog_breeds)
    +
    ## Already contains this dog
    +
    add_dog(dog_to_add = "German Shepard",
    +        input_vector = dog_breeds)
    ## [1] "German Shepard"     "Labrador Retriever" "Akita"             
     ## [4] "Bulldog"
    +
    +
    +

    Poll 6

    +

    What does this function do?

    +
    mystery_function <- function(x) {
    +  if (x > 0) {
    +    return(x)
    +  } else {
    +    return(-x)
    +  }
    +}
    +
      +
    1. Returns the absolute value of x
    2. +
    3. Returns x
    4. +
    5. Returns the square root of x
    6. +
    7. Returns -x
    8. +
    diff --git a/docs/Intro_to_R_data_analysis_part_2.html b/docs/Intro_to_R_data_analysis_part_2.html index 799a650..48e5900 100644 --- a/docs/Intro_to_R_data_analysis_part_2.html +++ b/docs/Intro_to_R_data_analysis_part_2.html @@ -3862,7 +3862,7 @@ modified by adding layers

    10 min break

    -
    +
    10:00
    diff --git a/intro-r-data-analysis/Intro_to_R_data_analysis_part_1.Rmd b/intro-r-data-analysis/Intro_to_R_data_analysis_part_1.Rmd index 7b994e6..0c56716 100644 --- a/intro-r-data-analysis/Intro_to_R_data_analysis_part_1.Rmd +++ b/intro-r-data-analysis/Intro_to_R_data_analysis_part_1.Rmd @@ -35,8 +35,8 @@ Senior Statistician **What is your level of experience with coding/data analysis?** -1. I am fluent in another data analysis programming language (Python, Matlab etc.) -2. I am use Excel to do linear regression +1. I know another data analysis programming language (Python, Matlab etc.) +2. I can use Excel to do linear regression 3. I know some R 4. All of the above 5. None of the above @@ -119,6 +119,7 @@ feature rich graphical user interface (GUI) - Let's create an `Rmd` file in `RStudio` to explore the basics of how they work: - File -\> New File -\> R Markdown + ## R Markdown Advanced Usage - **Presentations:** Creating slides (like these) with [revealjs](https://github.com/rstudio/revealjs). @@ -175,16 +176,26 @@ DogBreeds <- c("Labrador Retriever", "Akita", "Bulldog") ## Data Types - Integer - - Whole numbers + - Whole numbers (in R denote with L ex. 1L,2L) - Numeric - Decimal numbers - Logical - Boolean (TRUE, FALSE) - - NA + - NA (missing data) - Character - Letters and strings of letters - "A", "Labrador Retriever" +## Poll 3 + +**Which of these is not the correct data type for the value?** + +1. 1.5 - Numeric +2. "Labrador Retriever" - Character +3. NA - Logical +4. 1 - Integer + + ## Data Structures - Vectors - Atomic vectors - one dimensional lists that store values of @@ -197,7 +208,7 @@ DogBreeds <- c("Labrador Retriever", "Akita", "Bulldog") - Data frames - Columns and rows of **mixed types** -## +## ![Data structures](assets/data structures.png) @@ -242,6 +253,19 @@ x >= y # Greater than or equal to x %in% y # Is x in this vector y? ``` +## Poll 4 + +**What is the output of the following code?** + +```{r, eval = FALSE} +4 %in% as.character(c(1,2,3,4)) +``` + +1. TRUE +2. FALSE +3. NA + + ## Logical Operators - Logical operators can compare TRUE or FALSE values ```{r, eval=FALSE} @@ -251,9 +275,22 @@ y <- FALSE !x # Not x x | y # x or y x & y # x and y - ``` +## Poll 5 + +**What is the output of the following code?** +```{r, eval=FALSE} +x <- TRUE +y <- FALSE + +x & !y +``` + +1. TRUE +2. FALSE +3. NA + ## Conditional execution - Relational and logical operations allow for conditional @@ -308,6 +345,27 @@ add_dog(dog_to_add = "German Shepard", input_vector = dog_breeds) ``` +## Poll 6 + +**What does this function do?** + +```{r, eval = FALSE} +mystery_function <- function(x) { + if (x > 0) { + return(x) + } else { + return(-x) + } +} +``` + +1. Returns the absolute value of x +2. Returns x +3. Returns the square root of x +4. Returns -x + + + # Packages ## Packages