R - How to turn a loop to a function in R

前端 未结 1 406
陌清茗
陌清茗 2021-01-20 14:14

Thank you for your reading. I often find that I need to apply a function to slices of my data, and then bind the outputs. I usually build a loop for that purpose, but I am s

相关标签:
1条回答
  • 2021-01-20 14:45

    The plyr package was built specifically to deal with data manipulation problems like this. Check out some of the documentation on the webpage: http://had.co.nz/plyr/

    I don't exactly understand the round() syntax you used, but I believe an equivalent plyr call would be

    library(plyr)
    ddply(s1, .(obs, session), transform, ds = round(clfdMc, 2), cs = round(cfdMc, 2))
    

    I'm not exactly sure this will do what you want. Your code is a little opaque.

    0 讨论(0)
提交回复
热议问题