Coder Social home page Coder Social logo

Comments (1)

LudvigOlsen avatar LudvigOlsen commented on June 7, 2024

Fixed both of these.

Then found that you can use unique(as.matrix(data), MARGIN=2) to do a similar thing and test against current approach:

code:

`set.seed(1)
df <- data.frame("participant" = factor(rep(c('1','2', '3', '4', '5', '6'), 3)),
"age" = rep(c(25,65,34), 3),
"diagnosis" = rep(c('a', 'b', 'a', 'a', 'b', 'b'), 3),
"score" = c(34,23,54,23,56,76,43,56,76,42,54,1,5,76,34,76,23,65))

df <- df %>% dplyr::arrange(participant, score)

system.time({
df_folded_100reps <- fold(df, 3, num_col = 'score', num_fold_cols=100,max_iters = 100)
})
`
Current approach:
user system elapsed
16.939 0.266 17.310

Using unique:
user system elapsed
247.794 4.186 253.402

So sticking to my own approach.
One reason for the difference may be, that I only compare two columns once, while unique can compare two columns up to 100 times in the example.

from groupdata2.

Related Issues (6)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.