x <- matrix(rnorm(10^7), ncol=4)
dim(x)
## [1] 2500000       4
# for
mx1 <- rep(NA, nrow(x))
system.time(for(i in 1:nrow(x)) mx1[i] <- max(x[i,]))
##    user  system elapsed 
##   1.544   0.004   1.550
# or apply?
system.time(mx2 <- apply(x, 1, max))
##    user  system elapsed 
##   4.052   0.032   4.085
identical(mx1,mx2)
## [1] TRUE
# why's that??
# 'for' loop is not slow... that memory allocation and object's copying is slow:
mx4 <- NULL
system.time(for(i in 1:nrow(x)) mx4 <- c(mx4, max(x[i,])))
##     user   system  elapsed 
## 6281.944  151.892 6434.270