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

From: Ido M. Tamir <tamir_at_imp.univie.ac.at>
Date: Mon 05 Dec 2005 - 03:07:14 EST


Serguei Kaniovski wrote:

> 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 and a 3D plot of (i,x(i),y(i)), i.e. for
> each iteration
>
> Thanks,
> Serguei Kaniovski

If thats all you really need:
data<- t(sapply(1:5, function(i){ return(c(i,i^2,i^3))})) scatterplot3d(data)

In general you don't plot something in R for each iteration. You rather pass the whole result to the plot function. But there are plotting function which accept formulas.

Regards,
Ido Tamir



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 04:15:45 2005

This archive was generated by hypermail 2.1.8 : Mon 05 Dec 2005 - 09:24:51 EST