Skip to content

Commit d46698a

Browse files
authored
Merge pull request rstudio-education#11 from strboul/master
Insert missing curly brackets in system.time call
2 parents c0aa126 + d538d69 commit d46698a

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

speed.rmd

+5-5
Original file line numberDiff line numberDiff line change
@@ -256,25 +256,25 @@ You can dramatically increase the speed of your `for` loops by doing two things
256256
Second, make sure that any storage objects that you use with the loop are large enough to contain _all_ of the results of the loop. For example, both loops below will need to store one million values. The first loop stores its values in an object named `output` that begins with a length of _one million_:
257257

258258
```r
259-
system.time(
259+
system.time({
260260
output <- rep(NA, 1000000)
261261
for (i in 1:1000000) {
262262
output[i] <- i + 1
263263
}
264-
)
264+
})
265265
## user system elapsed
266266
## 1.709 0.015 1.724
267267
```
268268

269269
The second loop stores its values in an object named `output` that begins with a length of _one_. R will expand the object to a length of one million as it runs the loop. The code in this loop is very similar to the code in the first loop, but the loop takes _37 minutes_ longer to run than the first loop:
270270

271271
```r
272-
system.time(
272+
system.time({
273273
output <- NA
274274
for (i in 1:1000000) {
275275
output[i] <- i + 1
276276
}
277-
)
277+
})
278278
## user system elapsed
279279
## 1689.537 560.951 2249.927
280280
```
@@ -505,4 +505,4 @@ knitr::include_graphics("images/hopr_1004.png")
505505

506506
A well-rounded data scientist will need to be able to solve each of these problems in many different situations. By learning to program in R, you have mastered the logistical problem, which is a prerequisite for solving the tactical and strategic problems.
507507

508-
If you would like to learn how to reason with data, or how to transform, visualize, and explore your data sets with R tools, I recommend the book [_R for Data Science_](http://r4ds.had.co.nz/), the companion volume to this book. _R for Data Science_ teaches a simple workflow for transforming, visualizing, and modeling data in R, as well as how to report results with the R Markdown package.
508+
If you would like to learn how to reason with data, or how to transform, visualize, and explore your data sets with R tools, I recommend the book [_R for Data Science_](http://r4ds.had.co.nz/), the companion volume to this book. _R for Data Science_ teaches a simple workflow for transforming, visualizing, and modeling data in R, as well as how to report results with the R Markdown package.

0 commit comments

Comments
 (0)