Hello everyone, I would like to create a "dynamic" array to keep storing number in it for (i in c(2:length(final))){ myarray <-final[i]-final[i-1] myarray2<-2*final[i] } At the end I would like to use myarray as the x values of an array and the myarray2 as the yvalues of the same array. I tried cbind but it didnot work. Could you please help me with that? Best Regards Alex [[alternative HTML version deleted]]
Hello Alex. I'm a bit confused by your english, but what I guess you want is: x<-final[-1] - final[-length(final)] y<-2*final[-1] result<-cbind(x=x, y=y) Good luck. Nick Sabbe -- ping: nick.sabbe at ugent.be link: http://biomath.ugent.be wink: A1.056, Coupure Links 653, 9000 Gent ring: 09/264.59.36 -- Do Not Disapprove -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Alaios Sent: woensdag 27 oktober 2010 16:38 To: Rhelp Subject: [R] keep adding elements to the matrix Hello everyone, I would like to create a "dynamic" array to keep storing number in it for (i in c(2:length(final))){ myarray <-final[i]-final[i-1] myarray2<-2*final[i] } At the end I would like to use myarray as the x values of an array and the myarray2 as the yvalues of the same array. I tried cbind but it didnot work. Could you please help me with that? Best Regards Alex [[alternative HTML version deleted]] ______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
On Oct 27, 2010, at 10:37 AM, Alaios wrote:> Hello everyone, > I would like to create a "dynamic" array to keep storing number in it > > > for (i in c(2:length(final))){ > myarray <-final[i]-final[i-1] > myarray2<-2*final[i] > }Because there are no indices on the left hand side of those assignments, you are just overwriting those values. If you want myarray and myarray2 to actually be vectors, (or matrices or arrays), then you need to create them with the proper dimension(s) and then index them when assigning into them.> > At the end I would like to use myarray as the x values of an array > and the myarray2 as the yvalues of the same array.Perhaps myarray <- matrix(NA, nrow=length(final)-1, ncol=2) myarray[ , 1] <- diff(final) myarray[ , 2] <- 2*final[2:length(final)]> I tried cbind but it didnot work. > > Could you please help me with that?David Winsemius, MD West Hartford, CT