Skip to content

Commit

Permalink
Use consistent indentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Bisaloo committed Jul 12, 2024
1 parent 8172962 commit 5822b31
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 24 deletions.
12 changes: 6 additions & 6 deletions episodes/02-func-R.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ You can write your own functions in order to make repetitive operations using a

```{r, include=FALSE}
my_function <- function(input) {
# perform action and produce output
return(output) # return output value
# perform action and produce output
return(output) # return output value
}
```

Expand Down Expand Up @@ -177,10 +177,10 @@ Write a function called `edges` that returns a vector made up of just the first

```{r, echo=-1}
edges <- function(v) {
first <- v[1]
last <- v[length(v)]
answer <- c(first, last)
return(answer)
first <- v[1]
last <- v[length(v)]
answer <- c(first, last)
return(answer)
}
dry_principle <- c("Don't", "repeat", "yourself", "or", "others")
edges(dry_principle)
Expand Down
20 changes: 10 additions & 10 deletions episodes/04-cond.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ Two vertical bars, `||`, symbolize "or".

```{r}
if (1 > 0 && -1 > 0) {
print("both parts are true")
print("both parts are true")
} else {
print("at least one part is not true")
}
Expand All @@ -185,7 +185,7 @@ while `||` is true if either part is true:

```{r}
if (1 > 0 || -1 > 0) {
print("at least one part is true")
print("at least one part is true")
} else {
print("neither part is true")
}
Expand Down Expand Up @@ -239,11 +239,11 @@ To do this you'll use the R functions `boxplot` and `stripchart`.

```{r using-conditions-01, echo=-1}
plot_dist <- function(x, threshold) {
if (length(x) > threshold) {
boxplot(x)
} else {
stripchart(x)
}
if (length(x) > threshold) {
boxplot(x)
} else {
stripchart(x)
}
}
dat <- read.csv("data/inflammation-01.csv", header = FALSE)
plot_dist(dat[, 10], threshold = 10) # day (column) 10
Expand Down Expand Up @@ -285,11 +285,11 @@ A histogram is made with the `hist` command in R.
```{r conditional-challenge-hist, fig.alt=c("A grey unlabeled boxplot chart showing the distrubution values between 2 and 9 with a mean at 6.", "A grey unlabeled histogram showing bimodal distribution between 2 and 9 with peaks at 2 and 6.", "A mostly blank strip chart showing five points at 3, 4, 6, 7, and 9"), echo=-1}
plot_dist <- function(x, threshold, use_boxplot = TRUE) {
if (length(x) > threshold && use_boxplot) {
boxplot(x)
boxplot(x)
} else if (length(x) > threshold && !use_boxplot) {
hist(x)
hist(x)
} else {
stripchart(x)
stripchart(x)
}
}
dat <- read.csv("data/inflammation-01.csv", header = FALSE)
Expand Down
15 changes: 8 additions & 7 deletions episodes/11-supp-read-write-csv.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ carSpeeds <- read.csv(file = 'data/car-speeds.csv')
# Replace 'Blue' with 'Green' in cars$Color without using the stringsAsFactors
# or as.is arguments
carSpeeds$Color <- ifelse(as.character(carSpeeds$Color) == 'Blue',
'Green',
as.character(carSpeeds$Color))
'Green',
as.character(carSpeeds$Color))
# Convert colors back to factors
carSpeeds$Color <- as.factor(carSpeeds$Color)
```
Expand All @@ -167,11 +167,12 @@ carSpeeds <- read.csv(file = 'data/car-speeds.csv')
# Replace 'Blue' with 'Green' in cars$Color without using the stringsAsFactors
# or as.is arguments
carSpeeds$Color <-
ifelse(as.character(carSpeeds$Color) == 'Blue',
carSpeeds$Color <- ifelse(
as.character(carSpeeds$Color) == 'Blue',
'Green',
as.character(carSpeeds$Color))
as.character(carSpeeds$Color)
)
# Convert colors back to factors
carSpeeds$Color <- as.factor(carSpeeds$Color)
```
Expand All @@ -197,7 +198,7 @@ carSpeeds <- read.csv(
stringsAsFactors = FALSE,
strip.white = TRUE,
sep = ','
)
)
unique(carSpeeds$Color)
```
Expand Down
3 changes: 2 additions & 1 deletion episodes/13-supp-data-structures.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,8 @@ Consider the following matrix:
FOURS <- matrix(
c(4, 4, 4, 4),
nrow = 2,
ncol = 2)
ncol = 2
)
```

Given that `typeof(FOURS[1])` returns `"double"`, what would you expect
Expand Down

0 comments on commit 5822b31

Please sign in to comment.