Construct a data.frame in a FOR-loop
Say I have a FOR-loop for computing powers (just a trivial example)
for(i in 1:5)
{
x<-i^2
y<-i^3
}
How can I create a data.frame
x<-numeric(5)
y<-numeric(5)
for(i in 1:5)
+ {
+ x[i]<-i^2
+ y[i]<-i^3
+ }
da<-data.frame(index=1:5,x=x,y=y) da
index x y 1 1 1 1 2 2 4 8 3 3 9 27 4 4 16 64 5 5 25 125 these can get the data frame.
and a 3D plot of (i,x(i),y(i)), i.e. for each iteration Thanks, Serguei Kaniovski --
___________________________________________________________________ ÂÖsterreichisches Institut fÂür Wirtschaftsforschung (WIFO) Name: Serguei Kaniovski Postadresse: Postfach 91 Tel.: +43-1-7982601-231 A-1103 Wien Fax : +43-1-7989386 Standort: Arsenal Objekt 20 Mail: Serguei.Kaniovski at wifo.ac.at A-1030 Wien http://www.wifo.ac.at/ ______________________________________________ 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
= = = = = = = = = = = = = = = = = = = = 2005-12-04 ------ Deparment of Sociology Fudan University My new mail addres is ronggui.huang at gmail.com Blog:http://sociology.yculblog.com