Instantly share code, notes, and snippets.

Created April 19, 2024 12:03
The example of a function definition discussed in the recap session on April 19.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 # A step-by-step solution for the first function task of the "Basics" tutorial # Goal: define a function that computes the sample variance of a vector # Note: there are many strategies to develop functions; here we start by first # writing the code that solves our problem for one particular case outside the # function, and then generalize this code in a function. # First step: think about the starting point for your function. In our case: # we start with a vector containing some numbers, because this is from what
Created April 18, 2024 09:52
Template file for working on the exercises for the first recap session.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 # remotes::install_github("graebnerc/DataScienceExercises") library(DataScienceExercises) library(tibble) # # Exercise 1: Basic object types I--------- # # 1. Create a vector containing the numbers `2`, `5`, `2.4` and `11`. # # 2. Replace the second element with `5.9`. #
Created April 18, 2024 09:30
Solutions to the intermediate exercises of the session on basic object types.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 # Task 1: Intermediate exercises I=============== # Create a vector containing the numbers 2, 5, 2.4 and 11. vec_task_1 <- c(2, 5, 2.4, 11) # What is the type of this vector? typeof(vec_task_1) # Transform this vector into the type integer. What happens? typeof(vec_task_1)
Created March 25, 2024 21:53
Data Science Using R (Spring 2024) - Session 4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 # Session Script on Advanced object types (Spring Semester 2024) # Digression ff <- factor(c("F", "M", "M"), levels = c("F", "M", "D")) attributes(ff) # See the class attribute 'factor' typeof(ff) # It still remains an integer type... class(ff) # but the class was changed # Factors--------------------
Last active March 24, 2024 08:05
Data Science Using R (Spring 2024) - Session 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 # This is the script that we developed during the session on March 21, 2024 # 1. Basic commands----------- # This is an addition: 2 + 4 4 - 9 # This is substraction 4/9 3*9 2**3
Last active June 25, 2023 22:58
The examples used during session 17 and 18 on multiple linear regression, as well as possible solutions to the exercises.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 Contains solutions to the exercises as well as the code used to create the relevant figures in the slides. The code assumes a standard folder structure and might need to be adjusted to your case.
Created June 22, 2023 15:13
In-class solutions for the recap session.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 here::i_am("inclass-regression-solution.R") library(here) library(dplyr) library(tidyr) library(data.table) library(ggplot2) # Step 1: import data---------- reg_data <- data.table::fread(here("data/reg_data_1.csv")) %>% as_tibble()
Last active June 2, 2023 09:32
The script used during session 14 on sampling theory, as well as possible solutions to the exercises.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 This is the script we used during the lecture. For a version that is better documented but essentially covers the same issues, see the tutorial on Monte Carlo Simulations: https://euf-datascience-spring23.netlify.app/tutorial/mcs/pubdir/onlinecontent.html
Created May 11, 2023 13:59
#S12 - Recap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 This contains the script developed during the recap session.
Created May 4, 2023 19:16
The script used during session 10.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 The script using during session 10. For more precise solutions see: https://gist.github.com/graebnerc/5d5ec7591a45d6cbad3a58ddf06fff6b