Take the 2-minute tour ×  This question already has an answer
here:  In R, I create a data frame in a following way:  data <-
data.frame(dummy=rep('dummy',10000)) data$number = 0
data$another = 1  When I run a for loop that assigns values to
data frame (iterating through rows), my code runs infinitely
slow  calculation <- function() {2} somethingElse <- function()
{3}   for (i in 1:10000) {  The above snippet runs in 20 seconds
on my laptop. In other languages like C or Java, this finishes
instantly. Why is it so slow in R? I remember reading that R
stores matrices column by column (unlike C, for example, where
it's row by row). But still, I'm puzzled about why it takes so
much time. Shouldn't my data.frame fit comfortably in memory
(eluding slow disk write behavior)?  As a continuation of my
question, I'd like to ask for a quick way to fill my data frame
by row, if there exists one.  EDIT: Please note that I'm not
trying to assign constants 2 and 3 to my data frame, in the
actual problem that I was trying to