Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 984505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T05:01:38+00:00 2026-05-16T05:01:38+00:00

Thank you for your reading. I often find that I need to apply a

  • 0

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 sure I am doing it wrong, and that in R I should be using a different way of thinking. Can you please help me learn a better way to do this?

With thanks,

adam

    rm(m); m=0; # this variable will hold the output of the loop
    for (nobs in as.numeric(levels(factor(s1$obs)))) { # go over observer index
       for (nses in as.numeric(levels(factor(subset(s1, obs==nobs)$session)))) { # go over session index
          ns1=subset(s1, obs== nobs & session==nses & ky %in% c(1,2)); # the data slice of interest
          ds=round( clfdMc (ns1),2); cs=round( cfdMc (ns1),2); # apply function to data slice
          rw=cbind(nobs,nses,ds[2,3],ds[3,3],ds[2,3]-ds[3,3], cs[1,3],cs[2,3],nobs+nses/10, ds[2,4],ds[3,4],cs[1,4],cs[2,4]) # create a row from function output
          m=rbind(m,rw); #print(paste('obs:',nobs,' nses:',nses,'clear d:',ds[2,3],'red d',ds[3,3]))# bind new row to previous rows
        }
    }

m=data.frame(m[2:dim(m)[1],]) # create a data frame from these results
names(m)=c('obs','ses','D_clear','D_red','diffD','D_cg-1','D_cg+1','mark','C_clear','C_red','C_cg-1','C_cg+1') # give names to column variables
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T05:01:38+00:00Added an answer on May 16, 2026 at 5:01 am

    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
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I often want to trigger a certain function just once, but I need to
thanks for your reading. I am trying to modify Jquery Nivo Zoom plugin to
Thank you for your interesting in my question. You can help me out from
First of all thank you for your time and sorry if some issues are
Ok. here's the operations i successfully code so far thank's to your help: Adittion:
This one has me pretty rattled so I thank you in advance for your
Thanks for your help! I'd like to output all companyName entries that have uploads
I have been reading your posts and they are very helpful. However, I really
When asked to estimate and/or while reading my coworkers estimates they often read something
I remember reading somewhere that to really optimize & speed up certain section of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.