Get startedGet started for free

Why is this piece of code slow?

Consider the following piece of code:

x <- NULL
n <- 30000
for(i in 1:n) {
    x <- c(x, rnorm(1))
}

Which of the following statements is correct?

This exercise is part of the course

Writing Efficient R Code

View Course

Hands-on interactive exercise

Turn theory into action with one of our interactive exercises

Start Exercise