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
Code used during the lecture on sampling. |
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
Solutions for the exercises in the session on data preparation. |
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
library(DataScienceExercises) | |
library(ggplot2) | |
library(scales) | |
# Bubble plot------ | |
gdp_data <- DataScienceExercises::gdplifexp2007 | |
# In the following, lines with changes are marked with '# <---' | |
# 1st step: empty list | |
gdp_plot <- ggplot() |
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 |
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`. | |
# |
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) |
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-------------------- |
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 |
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() |
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. |
NewerOlder