compbio-2017 / Discussion

2 stars 1 forks source link

Performance Tips #5

Open shouldsee opened 7 years ago

shouldsee commented 7 years ago

Avoid slicing a data.frame within a for-loop, it will be VERY slow!

dat = data.frame(1:1000,1:1000)
mat = as.matrix(dat)
A = function(){ (for i in 1:1000){d=dat[i,]} }
B = function(){ (for i in 1:1000){d = mat[i,}}
sys.time(A())
sys.time(B())