[R] appending

From: Afshartous, David <afshart_at_exchange.sba.miami.edu>
Date: Thu 15 Jun 2006 - 02:31:36 EST


 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@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)
}

R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Thu Jun 15 02:36:28 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Thu 15 Jun 2006 - 04:11:17 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.