Skip to content

Commit

Permalink
differences for PR #31
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed May 16, 2024
1 parent 2792e73 commit 84132d3
Show file tree
Hide file tree
Showing 18 changed files with 232 additions and 247 deletions.
38 changes: 19 additions & 19 deletions 02-data-structures.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ numeric_vector <- c(2, 6, 3)
numeric_vector
```

```{.output}
```output
[1] 2 6 3
```

Expand All @@ -80,7 +80,7 @@ character_vector <- c('Amsterdam', 'London', 'Delft')
character_vector
```

```{.output}
```output
[1] "Amsterdam" "London" "Delft"
```

Expand All @@ -90,7 +90,7 @@ logical_vector <- c(TRUE, FALSE, TRUE)
logical_vector
```

```{.output}
```output
[1] TRUE FALSE TRUE
```

Expand All @@ -104,7 +104,7 @@ ab_vector <- c('a', 'b')
ab_vector
```

```{.output}
```output
[1] "a" "b"
```

Expand All @@ -113,7 +113,7 @@ abcd_vector <- c(ab_vector, 'c', 'd')
abcd_vector
```

```{.output}
```output
[1] "a" "b" "c" "d"
```

Expand Down Expand Up @@ -151,7 +151,7 @@ First, let's try to calculate mean for the values in this vector
mean(with_na) # mean() function cannot interpret the missing values
```

```{.output}
```output
[1] NA
```

Expand All @@ -161,7 +161,7 @@ mean(with_na) # mean() function cannot interpret the missing values
mean(with_na, na.rm = T)
```

```{.output}
```output
[1] 1.6
```

Expand All @@ -175,7 +175,7 @@ with `is.na()` function.
is.na(with_na) # This will produce a vector of logical values,
```

```{.output}
```output
[1] FALSE FALSE FALSE FALSE TRUE FALSE TRUE
```

Expand All @@ -186,7 +186,7 @@ is.na(with_na) # This will produce a vector of logical values,
!is.na(with_na) # The ! operator means negation, i.e. not is.na(with_na)
```

```{.output}
```output
[1] TRUE TRUE TRUE TRUE FALSE TRUE FALSE
```

Expand All @@ -202,7 +202,7 @@ without_na <- with_na[ !is.na(with_na) ] # this notation will return only
without_na
```

```{.output}
```output
[1] 1 2 1 1 3
```

Expand All @@ -229,7 +229,7 @@ nordic_str <- c('Norway', 'Sweden', 'Norway', 'Denmark', 'Sweden')
nordic_str # regular character vectors printed out
```

```{.output}
```output
[1] "Norway" "Sweden" "Norway" "Denmark" "Sweden"
```

Expand All @@ -239,7 +239,7 @@ nordic_cat <- factor(nordic_str)
nordic_cat # With factors, R prints out additional information - 'Levels'
```

```{.output}
```output
[1] Norway Sweden Norway Denmark Sweden
Levels: Denmark Norway Sweden
```
Expand All @@ -255,15 +255,15 @@ You can inspect and adapt levels of the factor.
levels(nordic_cat) # returns all levels of a factor vector.
```

```{.output}
```output
[1] "Denmark" "Norway" "Sweden"
```

```r
nlevels(nordic_cat) # returns number of levels in a vector
```

```{.output}
```output
[1] 3
```

Expand Down Expand Up @@ -295,7 +295,7 @@ nordic_cat <- factor(
nordic_cat
```

```{.output}
```output
[1] Norway Sweden Norway Denmark Sweden
Levels: Norway Denmark Sweden
```
Expand All @@ -320,7 +320,7 @@ nordic_cat <- fct_relevel(
nordic_cat
```

```{.output}
```output
[1] Norway Sweden Norway Denmark Sweden
Levels: Norway Denmark Sweden
```
Expand All @@ -336,7 +336,7 @@ You can also see the structure in the environment tab of RStudio.
str(nordic_cat)
```

```{.output}
```output
Factor w/ 3 levels "Norway","Denmark",..: 1 3 1 2 3
```

Expand All @@ -355,7 +355,7 @@ outside of this set, it will become an unknown/missing value detonated by
nordic_str
```

```{.output}
```output
[1] "Norway" "Sweden" "Norway" "Denmark" "Sweden"
```

Expand All @@ -370,7 +370,7 @@ nordic_cat2 <- factor(
nordic_cat2
```

```{.output}
```output
[1] Norway <NA> Norway Denmark <NA>
Levels: Norway Denmark
```
Expand Down
30 changes: 15 additions & 15 deletions 03-explore-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ It is important to see if all the variables (columns) have the data type that we
str(gapminder)
```

```{.output}
```output
'data.frame': 1704 obs. of 6 variables:
$ country : chr "Afghanistan" "Afghanistan" "Afghanistan" "Afghanistan" ...
$ year : int 1952 1957 1962 1967 1972 1977 1982 1987 1992 1997 ...
Expand All @@ -92,7 +92,7 @@ There are multiple ways to explore a data set. Here are just a few examples:
head(gapminder) # shows first 6 rows of the data set
```

```{.output}
```output
country year pop continent lifeExp gdpPercap
1 Afghanistan 1952 8425333 Asia 28.801 779.4453
2 Afghanistan 1957 9240934 Asia 30.332 820.8530
Expand All @@ -106,7 +106,7 @@ head(gapminder) # shows first 6 rows of the data set
summary(gapminder) # basic statistical information about each column.
```

```{.output}
```output
country year pop continent
Length:1704 Min. :1952 Min. :6.001e+04 Length:1704
Class :character 1st Qu.:1966 1st Qu.:2.794e+06 Class :character
Expand All @@ -129,15 +129,15 @@ summary(gapminder) # basic statistical information about each column.
nrow(gapminder) # returns number of rows in a dataset
```

```{.output}
```output
[1] 1704
```

```r
ncol(gapminder) # returns number of columns in a dataset
```

```{.output}
```output
[1] 6
```

Expand All @@ -155,7 +155,7 @@ country_vec <- gapminder$country
head(country_vec)
```

```{.output}
```output
[1] "Afghanistan" "Afghanistan" "Afghanistan" "Afghanistan" "Afghanistan"
[6] "Afghanistan"
```
Expand All @@ -176,7 +176,7 @@ year_country_gdp <- select(gapminder, year, country, gdpPercap)
head(year_country_gdp)
```

```{.output}
```output
year country gdpPercap
1 1952 Afghanistan 779.4453
2 1957 Afghanistan 820.8530
Expand All @@ -203,7 +203,7 @@ year_country_gdp <- gapminder %>%
head(year_country_gdp)
```

```{.output}
```output
year country gdpPercap
1 1952 Afghanistan 779.4453
2 1957 Afghanistan 820.8530
Expand All @@ -230,7 +230,7 @@ year_country_gdp_euro <- gapminder %>%
head(year_country_gdp_euro)
```

```{.output}
```output
year country gdpPercap
1 2002 Afghanistan 726.7341
2 2007 Afghanistan 974.5803
Expand Down Expand Up @@ -258,7 +258,7 @@ year_country_gdp_eurasia <- gapminder %>%
nrow(year_country_gdp_eurasia)
```

```{.output}
```output
[1] 756
```

Expand All @@ -276,7 +276,7 @@ gapminder %>% # select the dataset
summarize(avg_gdpPercap = mean(gdpPercap)) # create basic stats
```

```{.output}
```output
# A tibble: 5 × 2
continent avg_gdpPercap
<chr> <dbl>
Expand Down Expand Up @@ -306,7 +306,7 @@ gapminder %>%
avg_lifeExp == max(avg_lifeExp))
```

```{.output}
```output
# A tibble: 2 × 2
country avg_lifeExp
<chr> <dbl>
Expand All @@ -328,7 +328,7 @@ gapminder %>%
summarize(avg_gdpPercap = mean(gdpPercap))
```

```{.output}
```output
# A tibble: 60 × 3
# Groups: continent [5]
continent year avg_gdpPercap
Expand Down Expand Up @@ -370,7 +370,7 @@ gapminder %>%
count()
```

```{.output}
```output
# A tibble: 5 × 2
# Groups: continent [5]
continent n
Expand All @@ -395,7 +395,7 @@ gapminder_gdp <- gapminder %>%
head(gapminder_gdp)
```

```{.output}
```output
country year pop continent lifeExp gdpPercap gdpBillion
1 Afghanistan 1952 8425333 Asia 28.801 779.4453 6.567086
2 Afghanistan 1957 9240934 Asia 30.332 820.8530 7.585449
Expand Down
Loading

0 comments on commit 84132d3

Please sign in to comment.