Re: [R] Construct a data.frame in a FOR-loop

From: ronggui <042045003_at_fudan.edu.cn>
Date: Mon 05 Dec 2005 - 02:36:45 EST

>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@wifo.ac.at A-1030 Wien
>
>http://www.wifo.ac.at/
>
>______________________________________________
>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

2005-12-04



Deparment of Sociology
Fudan University

My new mail addres is ronggui.huang@gmail.com Blog:http://sociology.yculblog.com



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 Mon Dec 05 02:53:43 2005

This archive was generated by hypermail 2.1.8 : Mon 05 Dec 2005 - 04:24:14 EST