Skip to content

Commit 1784ada

Browse files
committed
making changes to set.seed example writing
1 parent f041787 commit 1784ada

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

classification2.Rmd

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -134,35 +134,34 @@ Here, we pass in the number `1`.
134134

135135
```{r}
136136
set.seed(1)
137-
random_numbers <- sample(0:9, 10, replace=TRUE)
138-
random_numbers
137+
random_numbers1 <- sample(0:9, 10, replace=TRUE)
138+
random_numbers1
139139
```
140140

141-
You can see that `random_numbers` is a list of 10 numbers
141+
You can see that `random_numbers1` is a list of 10 numbers
142142
from 0 to 9 that, from all appearances, looks random. If
143143
we run the `sample` function again, we will
144144
get a fresh batch of 10 numbers that also look random.
145145

146146
```{r}
147-
random_numbers <- sample(0:9, 10, replace=TRUE)
148-
random_numbers
147+
random_numbers2 <- sample(0:9, 10, replace=TRUE)
148+
random_numbers2
149149
```
150150

151151
If we want to force R to produce the same sequences of random numbers,
152152
we can simply call the `set.seed` function again with the same argument
153-
value.
153+
value.
154154

155155
```{r}
156156
set.seed(1)
157-
random_numbers <- sample(0:9, 10, replace=TRUE)
158-
random_numbers
157+
random_numbers1_again <- sample(0:9, 10, replace=TRUE)
158+
random_numbers1_again
159159
160-
set.seed(1)
161-
random_numbers <- sample(0:9, 10, replace=TRUE)
162-
random_numbers
160+
random_numbers2_again <- sample(0:9, 10, replace=TRUE)
161+
random_numbers2_again
163162
```
164163

165-
And if we choose
164+
Notice that after setting the seed, we get the same two sequences of numbers in the same order. `random_numbers1` and `random_numbers1_again` produce the same sequence of numbers, and the same can be said about `random_numbers2` and `random_numbers2_again`. And if we choose
166165
a different value for the seed&mdash;say, 4235&mdash;we
167166
obtain a different sequence of random numbers.
168167

@@ -171,7 +170,6 @@ set.seed(4235)
171170
random_numbers <- sample(0:9, 10, replace=TRUE)
172171
random_numbers
173172
174-
set.seed(4235)
175173
random_numbers <- sample(0:9, 10, replace=TRUE)
176174
random_numbers
177175
```

0 commit comments

Comments
 (0)