Thanks for reading. I often find that I need to apply a function to slices of my data, and then bind the outputs. I usually create a loop for this purpose, but I'm sure I am doing it wrong, and that in R I have to use a different way of thinking. Could you help me find out the best way to do this?
With thanks,
Adam
rm(m); m=0;
for (nobs in as.numeric(levels(factor(s1$obs)))) {
for (nses in as.numeric(levels(factor(subset(s1, obs==nobs)$session)))) {
ns1=subset(s1, obs== nobs & session==nses & ky %in% c(1,2));
ds=round( clfdMc (ns1),2); cs=round( cfdMc (ns1),2);
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])
m=rbind(m,rw);
}
}
m=data.frame(m[2:dim(m)[1],])
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')