Skip to content

Commit

Permalink
solved comments from reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
luisesanmartin committed Nov 20, 2020
1 parent dca24a2 commit f01041b
Show file tree
Hide file tree
Showing 6 changed files with 186 additions and 178 deletions.
122 changes: 58 additions & 64 deletions Presentations/01-intro-to-R-Part-I.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,14 @@ whr <- read.csv(file.path(finalData,"whr_panel.csv"),
1. [Installation](#installation)
2. [Introduction](#introduction)
3. [Getting started](#getting-started)
4. [RStudio interface](#rstudio-interface)
5. [Data in R](#data-in-r)
6. [Functions](#functions)
7. [R objects](#r-objects)
8. [Basic types of data](#basic-types-of-data)
9. [Advanced types of data](#advanced-types-of-data)
10. [Help, Google, and Stack Overflow](#help-google-and-stack-overflow)
11. [Useful resources](#useful-resources)
12. [Appendix](#appendix)
4. [Data in R](#data-in-r)
5. [Functions](#functions)
6. [R objects](#r-objects)
7. [Basic types of data](#basic-types-of-data)
8. [Advanced types of data](#advanced-types-of-data)
9. [Help, Google, and Stack Overflow](#help-google-and-stack-overflow)
10. [Useful resources](#useful-resources)
11. [Appendix](#appendix)

---

Expand Down Expand Up @@ -180,7 +179,7 @@ name: introduction

# Introduction

These training sessions will offer a quick introduction to R, its amazing features and why it is so much better than Stata.
These training sessions will offer an introduction to R, its amazing features and how Stata users can adapt to utilize the features that are better in R

---

Expand All @@ -190,7 +189,7 @@ This first session will present the basic concepts you will need to use R.

The next sessions will include:

* __Introduction to R part II__
* __Introduction to R - part II__

* __Data processing__

Expand Down Expand Up @@ -219,7 +218,7 @@ Some advantages of R over Stata:
+ More resources online, which makes using Google a lot easier. You'll never want to see Statalist again in your life!
+ Development of new features and bug fixes happen faster.

* It is waaaay cooler in general.
* It is cooler in general.

---

Expand All @@ -230,7 +229,9 @@ Some possible disadvantages of R:
* Higher cost of entry than Stata for learning how to use it.

* Stata is more specialized:
+ Certain common tasks are simpler in Stata.
+ Certain common tasks are simpler in Stata. For example:
* Running a regression with clustered standard errors
* Analyzing survey data with weights

* Stata has wider adoption among micro-econometricians (though R adoption is steadily increasing).
+ Network externalities in your work environment.
Expand Down Expand Up @@ -260,12 +261,12 @@ Here are some other advantages:

# Introduction

But Python is even more flexible and has more users than R, so why should I bother to learn R?
But Python is even more flexible and has more users than R, so why should I learn R?

* Despite being super popular for data science, Python has fewer libraries developed for econometrics.

* Python is a bit harder to set up and get started.

* It can be a harder to find help only for statistics and econometrics in Python than in R, especially for beginners.

---
Expand All @@ -279,89 +280,80 @@ name: getting-started

---

# Getting started

Let's start by loading the data set we'll be using:
# Getting started - RStudio interface

## Exercise 1: Import data

1. In RStudio, go to `File > Import Dataset > From Text (base)` and open the `whr_panel.csv` file.
+ Depending on your Rstudio version, it might be `File > Import Dataset > From CSV`

2. The file should be in `GitHub/dime-r-training/DataWork/DataSets/Final/whr_panel.csv`.

3. Assign the name `whr` to the dataset on the import window.
```{r echo = FALSE, out.width = "70%"}
knitr::include_graphics("img/Interface.png")
```

---

# Getting started
# Getting started - RStudio interface

```{r echo = FALSE, out.width = "50%"}
knitr::include_graphics("img/import_data1.png")
```{r echo = FALSE, out.width = "70%"}
knitr::include_graphics("img/environment.png")
```

---

# Getting started
# Getting started - RStudio interface

```{r echo = FALSE, out.width = "50%"}
knitr::include_graphics("img/import_data2.png")
```{r echo = FALSE, out.width = "70%"}
knitr::include_graphics("img/scritpt1.png")
```

---

class: inverse, center, middle
name: rstudio-interface

# RStudio interface

<html><div style='float:left'></div><hr color='#D38C28' size=1px width=1100px></html>
# Getting started - RStudio interface

```{r echo = FALSE, out.width = "70%"}
knitr::include_graphics("img/scritpt2.png")
```
---

# RStudio interface
# Getting started - RStudio interface

```{r echo = FALSE, out.width = "70%"}
knitr::include_graphics("img/Interface.png")
knitr::include_graphics("img/scritpt3.png")
```

---

# RStudio interface
# Getting started - RStudio interface

```{r echo = FALSE, out.width = "70%"}
knitr::include_graphics("img/environment.png")
knitr::include_graphics("img/scritpt4.png")
```

---

# RStudio interface
# Getting started - Importing data

```{r echo = FALSE, out.width = "70%"}
knitr::include_graphics("img/scritpt1.png")
```
Let's start by loading the data set we'll be using:

---
## Exercise 1: Import data

# RStudio interface
1. In RStudio, go to `File > Import Dataset > From Text (base)` and open the `whr_panel.csv` file.
+ Depending on your Rstudio version, it might be `File > Import Dataset > From CSV`

2. The file should be in `GitHub/dime-r-training/DataWork/DataSets/Final/whr_panel.csv`.

3. Assign the name `whr` to the dataset on the import window.

```{r echo = FALSE, out.width = "70%"}
knitr::include_graphics("img/scritpt2.png")
```
---

# RStudio interface
# Getting started - Importing data

```{r echo = FALSE, out.width = "70%"}
knitr::include_graphics("img/scritpt3.png")
```{r echo = FALSE, out.width = "50%"}
knitr::include_graphics("img/import_data1.png")
```

---

# RStudio interface
# Getting started - Importing data

```{r echo = FALSE, out.width = "70%"}
knitr::include_graphics("img/scritpt4.png")
```{r echo = FALSE, out.width = "50%"}
knitr::include_graphics("img/import_data2.png")
```

---
Expand Down Expand Up @@ -466,6 +458,8 @@ subset(whr, year == 2015)
head(whr)
```

#### Important: Always write your code in the script window and run it from there

---

# Data in R
Expand Down Expand Up @@ -525,7 +519,7 @@ head(whr2015)

```{r, echo= F}
# Use the head() function again
head(whr2015[,1:5])
head(whr2015)
```

---
Expand All @@ -538,7 +532,7 @@ head(whr)

```{r, echo= F}
# Use the head() function again
head(whr[,1:5])
head(whr)
```

---
Expand All @@ -553,7 +547,7 @@ You can also see that your environment pane now has two objects:

# Data in R

### Two important concepts to take note:
### Important concepts to take note:
1. In R, if you want to change your data, you need to __store it in an object__.

2. It is possible to simply replace the original data. This happens if you assign the new object to the same name as the original.
Expand Down Expand Up @@ -911,7 +905,7 @@ print(boolean_false)
Create a boolean vector with the condition of annual income below average:
```{r}
# Create vector
bool_vec <- whr$happy_rank < mean(whr$happy_rank)
bool_vec <- whr$happiness_score < mean(whr$happiness_score)
# See the 6 first elements of the vector
head(bool_vec)
Expand Down Expand Up @@ -951,7 +945,7 @@ Instead of indexing the lines with the boolean vector `bool_vec`, we could also
# Replace with 1 those obs that meet the condition
whr$rank_low [bool_vec] <- 1
# is the same as
whr$rank_low [whr$happy_rank < mean(whr$happy_rank)] <- 1
whr$rank_low [whr$happiness_score < mean(whr$happiness_score)] <- 1
# This in stata would be
# gen rank_low = 0
# replace rank_low = 1 if (...)
Expand Down
Loading

0 comments on commit f01041b

Please sign in to comment.