You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: 0_01_R_and_RStudio.Rmd
+1-1
Original file line number
Diff line number
Diff line change
@@ -16,7 +16,7 @@ R is not just about data analysis---though we will mostly use it this way. It is
16
16
17
17
### Getting and installing R {-}
18
18
19
-
R is open source, meaning anyone can download the source code -- the collection of computer instructions that define R -- and assuming they have enough time, energy and expertise, they are free to alter it as they please. Open source does not _necessarily_ mean free, as in it costs £0 to download and use, but luckily R _is_ free in this sense. If you are working on the University managed desktops it should already have been installed and is ready for you to use. We encourage you to install a copy on your own laptop so that you can work at home, in the library, at a café, or wherever else you find you are productive. Do not use R on its own though. Use it in combination with the RStudio IDE discussed in the next section.
19
+
R is open source, meaning anyone can download the source code -- the collection of computer instructions that define R -- and assuming they have enough time, energy and expertise, they are free to alter it as they please. Open source does not _necessarily_ mean free, as in it costs £0 to download and use, but luckily R _is_ free in this sense. If you're working on the University managed desktops it should already have been installed and is ready for you to use. We encourage you to install a copy on your own laptop so that you can work at home, in the library, at a café, or wherever else you find you are productive. Do not use R on its own though. Use it in combination with the RStudio IDE discussed in the next section.
20
20
21
21
In order to install R you need to download the appropriate installer from the Comprehensive R Archive Network ([CRAN](http://cran.r-project.org)). We are going to use the "base distribution" as this contains everything you need to use R under normal circumstances. There is a single [installer](http://cran.r-project.org/bin/windows/base/) for Windows. On a Mac, it's important to match the [installer](http://cran.r-project.org/bin/macosx/) to the version of OS X. In either case, R uses a the standard install mechanism that should be familiar to anyone who has installed an application on their machine. There is no need to change the default settings---doing so will probably lead to problems later on.
Copy file name to clipboardexpand all lines: 1_05_numeric_vectors.Rmd
+4-4
Original file line number
Diff line number
Diff line change
@@ -74,7 +74,7 @@ c(vec1, vec2)
74
74
```
75
75
This shows that we can use the `c` function to concatenate ("stick together") two or more vectors, even if they are not of length 1. We combined a length-2 vector with a length-3 vector to produce a new length-5 vector.
76
76
77
-
Notice that we did not have to name the arguments in those two examples---there were no `=` involved. The `c` function is an example of one of those flexible functions that breaks the simple rules of thumb for using arguments that we set out earlier: it can take a variable number of arguments, and these arguments do not have predefined names. This behaviour is necessary if you think about how `c`has to work: in order to be useful it needs to be flexible enough to take any combination of arguments.
77
+
Notice that we did not have to name the arguments in those two examples---there were no `=` involved. The `c` function is an example of one of those flexible functions that breaks the simple rules of thumb for using arguments that we set out earlier: it can take a variable number of arguments, and these arguments do not have predefined names. This behaviour is necessary for `c` to be of any use: in order to be useful it needs to be flexible enough to take any combination of arguments.
78
78
79
79
```{block, type="info"}
80
80
#### Finding out about a vector R
@@ -111,7 +111,7 @@ This is fairly self-explanatory. The `seq` function constructed a numeric vector
111
111
```{r}
112
112
seq(from = 0, to = 11, by = 2)
113
113
```
114
-
You can generate a descending sequence by using a negative `by` value, like this:
114
+
We can generate a descending sequence by using a negative `by` value, like this:
115
115
```{r}
116
116
seq(from = 12, to = 0, by = -2)
117
117
```
@@ -139,7 +139,7 @@ When we leave out the name of the third argument its value is position matched t
139
139
```{r}
140
140
seq(0, 12, 2)
141
141
```
142
-
However, our advice is to explicitly name the `by` argument instead of relying on position matching, because this will remind you what you're doing and will stop you forgetting about the different control arguments.
142
+
However, our advice is to explicitly name the `by` argument instead of relying on position matching, because this reminds us what we're doing and will stop us forgetting about the different control arguments.
143
143
144
144
If we do not specify values of either `by`, `length.out` and `along.with` when using `seq` the default behaviour is to assume we meant `by = 1`:
145
145
```{r}
@@ -176,7 +176,7 @@ Predictably, we can also use both the `times` and `each` arguments together if w
176
176
seqvec <- 1:4
177
177
rep(seqvec, times = 3, each = 2)
178
178
```
179
-
The way to think about how this works is to imagine that you apply `rep` twice, first with `each = 2`, then with `times = 3` (or vice versa). We can achieve the same thing using nested function calls, though it is much uglier:
179
+
The way to think about how this works is to imagine that we apply `rep` twice, first with `each = 2`, then with `times = 3` (or vice versa). We can achieve the same thing using nested function calls, though it is much uglier:
Copy file name to clipboardexpand all lines: 1_06_more_vectors.Rmd
+2-2
Original file line number
Diff line number
Diff line change
@@ -46,7 +46,7 @@ What about the `seq` function? Hopefully it is fairly obvious that we can't use
46
46
47
47
## Logical vectors
48
48
49
-
The elements of __logical vectors__ only take two values: `TRUE` or `FALSE`. Don't let the simplicity of logical vectors fool you---they're very useful. As with other kinds of atomic vectors the `c` and `rep` functions can be used to construct a logical vector:
49
+
The elements of __logical vectors__ only take two values: `TRUE` or `FALSE`. Don't let the simplicity of logical vectors fool you. They're very useful. As with other kinds of atomic vectors the `c` and `rep` functions can be used to construct a logical vector:
50
50
```{r}
51
51
l_vec <- c(TRUE, FALSE)
52
52
rep(l_vec, times = 2)
@@ -75,7 +75,7 @@ Now, if we need to evaluate and represent a question like, "is x greater than th
75
75
```{r}
76
76
x > y
77
77
```
78
-
What do you notice about this simple example? The `x > y` expression produces a logical vector, with `TRUE` values associated with elements in `x` are less than `y`, and `FALSE` otherwise. In this example, x is less than y until we reach the value of 15 in each sequence. Notice that that relational operators are vectorised: the work on an element by element basis. They wouldn't be much use if this were not the case.
78
+
The `x > y` expression produces a logical vector, with `TRUE` values associated with elements in `x` are less than `y`, and `FALSE` otherwise. In this example, x is less than y until we reach the value of 15 in each sequence. Notice that that relational operators are vectorised: the work on an element by element basis. They wouldn't be much use if this were not the case.
79
79
80
80
What does the `==` operator do? It compares the elements of two vectors to determine if they are exactly equal:
0 commit comments