From 83864badf85b53cacdc652b984703696cbe7e1f0 Mon Sep 17 00:00:00 2001 From: shoili Date: Wed, 18 Nov 2015 11:55:15 +0530 Subject: [PATCH 1/2] Typo correction in file expressing-yourself.Rmd The discussion of the code in lines 236-243 was a little confusing with x and y so I proposed changing it to a and b. Not sure if that was just an error that crept in while rewriting and fiddling around with the sentence or a conscious decision from you. --- expressing-yourself.Rmd | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/expressing-yourself.Rmd b/expressing-yourself.Rmd index 286fc59..19b7438 100644 --- a/expressing-yourself.Rmd +++ b/expressing-yourself.Rmd @@ -217,7 +217,7 @@ The pipe is a powerful tool, but it's not the only tool at your disposal, and it ## Duplication -As you become a better R programming, you'll learn more techniques for reducing various types of duplication. This allows you to do more with less, and allows you to express yourself more clearly by taking advantage of powerful programming constructs. +As you become a better R programmer, you'll learn more techniques for reducing various types of duplication. This allows you to do more with less, and allows you to express yourself more clearly by taking advantage of powerful programming constructs. Two main tools for reducing duplication are functions and for-loops. You tend to use for-loops less often in R than in other programming languages because R is a functional programming language. That means that you can extract out common patterns of for loops and put them in a function. @@ -243,7 +243,7 @@ df$d <- (df$d - min(df$d, na.rm = TRUE)) / (max(df$d, na.rm = TRUE) - min(df$d, na.rm = TRUE)) ``` -You might be able to puzzle out that this rescales each column to 0--1. Did you spot the mistake? I made an error when updating the code for `df$y`, and I forgot to change an `x` to a `y`. Extracting repeated code out into a function is a good idea because it helps make your code more understandable (because you can name the operation), and it prevents you from making this sort of update error. +You might be able to puzzle out that this rescales each column to 0--1. Did you spot the mistake? I made an error when updating the code for `df$b`, and I forgot to change an `a` to a `b`. Extracting repeated code out into a function is a good idea because it helps make your code more understandable (because you can name the operation), and it prevents you from making this sort of update error. To write a function you need to first analyse the operation. How many inputs does it have? @@ -275,7 +275,7 @@ rescale01 <- function(x) { } ``` -Always make sure you code works on a simple test case before creating the function! +Always make sure your code works on a simple test case before creating the function! Now we can use that to simplify our original example: @@ -304,7 +304,7 @@ for (i in 1:ncol(df)) { medians ``` -If you do this a lot, you'd probably pull make a function for it: +If you do this a lot, you should probably make a function for it: ```{r} col_medians <- function(df) { From 6b47330ea41847d6501d77097edbd5aecd9098fd Mon Sep 17 00:00:00 2001 From: Brandon Greenwell Date: Tue, 1 Dec 2015 14:27:35 -0500 Subject: [PATCH 2/2] Change `*` to `$` in Anchors Section of strings.Rmd I'm just learning regular expressions, but I think you meant to use $ instead of * in the second bullet point in the section titled Anchors in strings.Rmd. --- strings.Rmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/strings.Rmd b/strings.Rmd index e3bd375..3e4dc1c 100644 --- a/strings.Rmd +++ b/strings.Rmd @@ -248,7 +248,7 @@ In this book, I'll write a regular expression like `\.` and the string that repr By default, regular expressions will match any part of a string. It's often useful to _anchor_ the regular expression so that it matches from the start or end of the string. You can use: * `^` to match the start of the string. -* `*` to match the end of the string. +* `$` to match the end of the string. ```{r} x <- c("apple", "banana", "pear")