[R] appending
Afshartous, David
afshart at exchange.sba.miami.edu
Wed Jun 14 18:31:36 CEST 2006
All,
In the function below I have 24 individuals and 6 calculations per
individual.
The 6 calculations are collected each time in a 1:24 loop when
calculating "delta".
I'd like to collect all 144 = 24*6 calculations in one vector
("delta.patient.comb").
The function works as is via indexing, but is there an easier way to
collect the measurements via appendinng the 6 measurements each time to
the current set? I couldn't find anything in Intro to R on appending.
cheers,
Dave
ps - please respond directly to afshar at miami.edu
creatine.function.new = function(delta.0.Y.0, gamma, comp.LIS.frm,
comp.CAND.frm) { ## function to calcuate the delta.i, i.e. the percent
## leftover ## gamma = rate of Cr going into bucket, e.g., mg/hr ##
delta.0.Y.0 = product of delta.0 and Y.0 at baseline ##
Y.1 = delta.0.Y.0 + gamma
delta = numeric(6)
delta.patient = numeric(24)
delta.patient.comb = numeric(144)
##
for (k in 1:24) { ## each patient
patient.k.CAND = which(comp.CAND.frm$Patient_no == k)
Ucr.CAND.patient.k = comp.CAND.frm$Ucr[patient.k.CAND]
C = Ucr.CAND.patient.k ## 6 observed creatanine values
for each patient
delta[1] = (Y.1 - C[1])/Y.1
Y.i = Y.1
delta.i = delta[1]
for (i in 1:5) { ## six measurments per
patient
Y.i.plus.1 = delta.i * Y.i + gamma
delta.i.plus.1 = (Y.i.plus.1 -
C[i+1])/Y.i.plus.1
delta[i+1] = delta.i.plus.1
delta.i = delta[i+1]
Y.i = Y.i.plus.1
}
delta.patient[k] = list(delta)
delta.patient.comb[(6*(k-1)+1):(6*(k-1)+ 6)] = delta
}
list(delta.patient, delta.patient.comb)
}
More information about the R-help
mailing list