hi, i'd like to calculate a temperatursum, adding the value of each element. let's say the data looks like this: x<-c(1,2,3,4,5) what i want to do, is ploting not the sum in the end but all the subresults, too, so my vector holds: x[i] [1] 1,3,6,10,15 here is what i tried, which seems to be right to me, bu doesn't work out: x<-c(1,2,3,4,5) i<-1 j<-1 z[j]<-x[i]+x[i+1] p<-z[j] j<-2:4 i<-3:5 z[j]<-z[j-1]+x[i] plot (c(p,z[j]) what i get is: [1] 6.0 12.0 9.2 18.0 any sugestions? lars
?cumsum Z On Thu, 12 May 2005 18:48:32 +0200 Lars wrote:> hi, > > i'd like to calculate a temperatursum, adding the value of each > element. let's say the data looks like this: > > x<-c(1,2,3,4,5) > what i want to do, is ploting not the sum in the end but all the > subresults, too, > so my vector holds: > x[i] > [1] > 1,3,6,10,15 > here is what i tried, which seems to be right to me, bu doesn't work > out: > > x<-c(1,2,3,4,5) > i<-1 > j<-1 > z[j]<-x[i]+x[i+1] > p<-z[j] > j<-2:4 > i<-3:5 > z[j]<-z[j-1]+x[i] > plot (c(p,z[j]) > > what i get is: > [1] 6.0 12.0 9.2 18.0 > > any sugestions? lars > > ______________________________________________ > R-help at 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 >
maybe you can find cumsum() helpful, e.g., cumsum(1:5) Best, Dimitris ---- Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/16/336899 Fax: +32/16/337015 Web: http://www.med.kuleuven.ac.be/biostat/ http://www.student.kuleuven.ac.be/~m0390867/dimitris.htm ----- Original Message ----- From: "Lars" <lars.claussen at pik-potsdam.de> To: <r-help at stat.math.ethz.ch> Sent: Thursday, May 12, 2005 6:48 PM Subject: [R] tempsum> hi, > > i'd like to calculate a temperatursum, adding the value of each > element. > let's say the data looks like this: > > x<-c(1,2,3,4,5) > what i want to do, is ploting not the sum in the end but all the > subresults, too, > so my vector holds: > x[i] > [1] > 1,3,6,10,15 > here is what i tried, which seems to be right to me, bu doesn't work > out: > > x<-c(1,2,3,4,5) > i<-1 > j<-1 > z[j]<-x[i]+x[i+1] > p<-z[j] > j<-2:4 > i<-3:5 > z[j]<-z[j-1]+x[i] > plot (c(p,z[j]) > > what i get is: > [1] 6.0 12.0 9.2 18.0 > > any sugestions? lars > > ______________________________________________ > R-help at 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 >