CommencerCommencer gratuitement

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?

Cet exercice fait partie du cours

Writing Efficient R Code

Afficher le cours

Exercice interactif pratique

Passez de la théorie à la pratique avec l’un de nos exercices interactifs

Commencer l’exercice