Displaying 1 result from an estimated 1 matches for "cpct5".
Did you mean:
cpct
2007 Dec 06
5
Help rewriting looping structure?
...ndividual
record?
##### tdat is my data frame
##### j is my field index
##### k is my record index
##### tsum is the sum of all values in field j
##### tmp is a vector containing the values in field j
##### tdat[k,paste("cpct,j,sep="")] creates new fields "cpct1",...,"cpct5"
for(j in 1:5) {
tsum<- sum(tdat[,j]);
for(k in 1:nrow(tdat)) {
td<- tdat[k,j];
tmp<-tdat[,j];
##### sum values <= to current value and divide by the total sum
tdat[k,paste("cpct,j,sep="")]<- sum(tmp[tmp <= td]) / tsum;
}
}
Thanks,
TLowe...