Skip to content

Commit

Permalink
Revision session 1.1 and 1.2
Browse files Browse the repository at this point in the history
Added slides part 1.1
Revisions rmd files session 1.1 and 1.2
  • Loading branch information
Kyri Janssen committed May 7, 2024
1 parent 60bd8aa commit 29a1527
Show file tree
Hide file tree
Showing 76 changed files with 6,083 additions and 31 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ urban datasets.

## Rendered Version of This Lesson

Version 1.0
Version 1.0

## Contact Information

Expand Down
14 changes: 1 addition & 13 deletions episodes/01-intro-to-r.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -189,19 +189,6 @@ To run all lines before the active line, you can use the keyboard shortcut
<kbd>Ctrl</kbd> + <kbd>Alt</kbd> + <kbd>B</kbd> on Windows/Linux or
<kbd>Command</kbd> + <kbd>option</kbd> + <kbd>B</kbd> on Mac.

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: callout

### Escaping

The console shows it's ready to get new commands with `>` sign.
It will show `+` sign if it still requires input for the command to be executed.

Sometimes you don't know what is missing/ you change your mind and
want to run something else, or your code is running much too long
and you just want it to stop.
The way to do it is to press <kbd>Esc</kbd>.

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

## Packages

Expand Down Expand Up @@ -317,6 +304,7 @@ download.file(
)
```
The data we just downloaded is data about country statistics, containing information on, for instance, GDP and life-expectancy. We will work with this data later this morning

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: callout

Expand Down
38 changes: 21 additions & 17 deletions episodes/02-data-structures.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ After completing this episode, participants should be able to…
::::::::::::::::::::::::::::::::::::::::::::::::

## Vectors
So far we've looked on individual values. Now we will move to a data structure
called vectors. Vectors are arrays of values of the same data type.
So far we've looked on individual values, such as x <- 100. Now we will move to a data structure
called vectors. Vectors are arrays of values of the same data type. So now we combine multiple values into one object:
x <- c(100, 200)

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: callout

Expand Down Expand Up @@ -63,19 +64,26 @@ Note that vector data in the geospatial context is different from vector data ty

You can create a vector with a `c()` function.

You can also inspect vectors with `str()` function. In factor vectors,
it shows the underlying values of each category.
You can also see the structure in the environment tab of RStudio.

```{r vectors}
# vector of numbers - numeric data type.
numeric_vector <- c(2, 6, 3)
numeric_vector
str(numeric_vector)
# vector of words - or strings of characters- character data type
character_vector <- c('Amsterdam', 'London', 'Delft')
# vector of words - or strings of characters- character data type. Note that we need to use '' to tell R that we are working with strings. If there is a ' mark in the string itselfs, such as s'Gravenhage, then we use ""
character_vector <- c('Amsterdam', "'s Gravenhage", 'Delft')
character_vector
str(character_vector)
# vector of logical values (is something true or false?)- logical data type.
logical_vector <- c(TRUE, FALSE, TRUE)
logical_vector
str(logical_vector)
```

Expand Down Expand Up @@ -105,7 +113,7 @@ Combine the `abcd_vector` with the `numeric_vector` in R. What is the data type

```
combined_vector <- c(abcd_vector, numeric_vector)
combined_vector
str(combined_vector)
```
The combined vector is a character vector. Because vectors can only hold one data type and `abcd_vector` cannot be interpreted as numbers, the numbers in `numeric_vector` are _coerced_ into characters.

Expand Down Expand Up @@ -139,7 +147,13 @@ is.na(with_na) # This will produce a vector of logical values,
# stating if a statement 'This element of the vector is a missing value'
# is true or not
#in order to see how many values are missing in our with_na vector, we can use the sum function
sum(is.na(with_na))
#if we want to identify the values that are not missing we write the following
!is.na(with_na) # The ! operator means negation, i.e. not is.na(with_na)
#and if we want to sum all the non-missing values we write
sum(!is.na(with_na))
```

Expand Down Expand Up @@ -181,7 +195,8 @@ nordic_str # regular character vectors printed out
# factor() function converts a vector to factor data type
nordic_cat <- factor(nordic_str)
nordic_cat # With factors, R prints out additional information - 'Levels'
nordic_cat
str(nordic_cat)
```

### Inspect factors
Expand Down Expand Up @@ -241,18 +256,7 @@ nordic_cat <- fct_relevel(
nordic_cat
```
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::


You can also inspect vectors with `str()` function. In factor vectors,
it shows the underlying values of each category.
You can also see the structure in the environment tab of RStudio.

```{r factor-reorder}
str(nordic_cat)
```

:::::::::::::::::::::::::::::::::::::::::::::::::::: callout

### Note of caution

Expand Down
Loading

0 comments on commit 29a1527

Please sign in to comment.