Skip to content

Performance Tips #5

@shouldsee

Description

@shouldsee

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())

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions