Skip to content

Commit

Permalink
Merge pull request swcarpentry#288 from swcarpentry/update_from_prs
Browse files Browse the repository at this point in the history
files from merged PRs
  • Loading branch information
chendaniely authored Jul 16, 2017
2 parents e5008ab + d6ed0b2 commit 70c2c4e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 24 deletions.
44 changes: 26 additions & 18 deletions _episodes/01-starting-with-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ To do all that, we'll have to learn a little bit about programming.

### Loading Data

Let's import the file called `inflammation-01.csv` into our R environment. To import the file, first we need to tell our computer where the file is. We do that by choosing a working directory, that is, a local directory on our computer containing the files we need. This is very important in R. If we forget this step well get an error message saying that the file does not exist. We can set the working directory using the function `setwd`. For this example, we change the path to our new directory at the desktop:
Let's import the file called `inflammation-01.csv` into our R environment. To import the file, first we need to tell our computer where the file is. We do that by choosing a working directory, that is, a local directory on our computer containing the files we need. This is very important in R. If we forget this step we???ll get an error message saying that the file does not exist. We can set the working directory using the function `setwd`. For this example, we change the path to our new directory at the desktop:


~~~
Expand Down Expand Up @@ -633,13 +633,13 @@ summary(dat[,1:4])
~~~
V1 V2 V3 V4
Min. :0 Min. :0.00 Min. :0.000 Min. :0.00
1st Qu.:0 1st Qu.:0.00 1st Qu.:1.000 1st Qu.:1.00
Median :0 Median :0.00 Median :1.000 Median :2.00
Mean :0 Mean :0.45 Mean :1.117 Mean :1.75
3rd Qu.:0 3rd Qu.:1.00 3rd Qu.:2.000 3rd Qu.:3.00
Max. :0 Max. :1.00 Max. :2.000 Max. :3.00
V1 V2 V3 V4
Min. :0 Min. :0.00 Min. :0.000 Min. :0.00
1st Qu.:0 1st Qu.:0.00 1st Qu.:1.000 1st Qu.:1.00
Median :0 Median :0.00 Median :1.000 Median :2.00
Mean :0 Mean :0.45 Mean :1.117 Mean :1.75
3rd Qu.:0 3rd Qu.:1.00 3rd Qu.:2.000 3rd Qu.:3.00
Max. :0 Max. :1.00 Max. :2.000 Max. :3.00
~~~
{: .output}
Expand Down Expand Up @@ -692,31 +692,31 @@ We'll learn why this is so in the next lesson.
> A subsection of a data frame is called a [slice]({{ page.root }}/reference/#slice).
> We can take slices of character vectors as well:
>
>
>
> ~~~
> animal <- c("m", "o", "n", "k", "e", "y")
> # first three characters
> animal[1:3]
> ~~~
> {: .r}
>
>
>
>
>
>
> ~~~
> [1] "m" "o" "n"
> ~~~
> {: .output}
>
>
>
>
>
>
> ~~~
> # last three characters
> animal[4:6]
> ~~~
> {: .r}
>
>
>
>
>
>
> ~~~
> [1] "k" "e" "y"
> ~~~
Expand All @@ -742,6 +742,14 @@ We'll learn why this is so in the next lesson.
> 2. `max(dat[3:7, 5])`
> 3. `max(dat[5, 3:7])`
> 4. `max(dat[5, 3, 7])`
>
> > ## Solution
> >
> > Answer: 3
> >
> > Explanation: You want to extract the part of the dataframe representing data for patient 5 from days three to seven. In this dataframe, patient data is organised in columns and the days are represented by the rows. Subscripting in R follows the `[i,j]` principle, where `i=columns` and `j=rows`. Thus, answer 3 is correct since the patient is represented by the value for i (5) and the days are represented by the values in j, which is a slice spanning day 3 to 7.
> >
> {: .solution}
{: .challenge}
> ## Slicing and Re-Assignment
Expand Down
2 changes: 1 addition & 1 deletion _episodes/02-func-R.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ Real-life functions will usually be larger than the ones shown here--typically h
> e.g. `x <- c("A", "B", "C")` creates a vector `x` with three elements.
> Furthermore, we can extend that vector again using `c`, e.g. `y <- c(x, "D")` creates a vector `y` with four elements.
> Write a function called `fence` that takes two vectors as arguments, called
> original` and `wrapper`, and returns a new vector that has the wrapper vector
> `original` and `wrapper`, and returns a new vector that has the wrapper vector
> at the beginning and end of the original:
>
>
Expand Down
6 changes: 3 additions & 3 deletions _episodes/08-making-packages-R.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,16 @@ Place each function into a separate R script and add documentation like this:


~~~
#' Convert Fahrenheit to Kelvin
#' Converts Fahrenheit to Kelvin
#'
#' This function converts input temperatures in Fahrenheit to Kelvin.
#' @param temp The input temperature.
#' @param temp The temperature in Fahrenheit.
#' @return The temperature in Kelvin.
#' @export
#' @examples
#' fahr_to_kelvin(32)
fahr_to_kelvin <- function(temp) {
#Converts Fahrenheit to Kelvin
kelvin <- ((temp - 32) * (5/9)) + 273.15
kelvin
}
Expand Down
4 changes: 2 additions & 2 deletions _episodes/15-supp-loops-in-depth.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ system.time(avg2 <- analyze2(filenames))

~~~
user system elapsed
0.023 0.000 0.023
0.038 0.000 0.039
~~~
{: .output}

Expand Down Expand Up @@ -249,7 +249,7 @@ system.time(avg3 <- analyze3(filenames))

~~~
user system elapsed
0.020 0.000 0.022
0.039 0.000 0.039
~~~
{: .output}

Expand Down

0 comments on commit 70c2c4e

Please sign in to comment.