Try this:

before your loop put this

output1 <- NULL

in the loop at the end put this

temp <- data.frame(cbind(k,n,lam,Q))
output1 <- rbind(output1,temp)

this should do the trick for you

Adrienne
NCSU

On Thu, Oct 21, 2010 at 12:52 PM, Etn <2nuzz...@gmail.com> wrote:

> Hi All,
>
> Apologies for the simplicity of my question, but I would be grateful for
> any
> advice. Thanks
>
> I'm trying to put the output from a for loop into a data frame, however I
> have not been successful.
>
> The steps I have taken are:
>
>
>
> *R-code:*
>
> >for (k in 1:(nt-1-n0) ){
> >    n<- n0-1+k
> >    lam=n/nt
> >    Q=x[n]
>
> > output1<-data.frame(cbind(k,n,lam,Q))
> > output1
> >  }
>
> > output1
>
>
> *R-Output *
>     k    n  lam   Q
> 1 14  18  0.9   18
>
>
> I would like the output in this format, but for all the values of k (i.e.
> 1-14 as opposed to just the last value)
>
>
> I have also tried
>
> *R-code:*
>
> > nt=20
> > n0=5
> > x=c(1:20)
> > for (k in 1:(nt-1-n0) ){
> >      n<- n0-1+k
> >      lam=n/nt
> >      Q=x[n]
>
> > output1<-data.frame(cbind(k,n,lam,Q))
> > print(output1)
> >  }
>
>
> *R-Output  *
>
>    k n  lam Q
> 1 1 5 0.25 5
>   k n lam Q
> 1 2 6 0.3 6
>   k n  lam Q
> 1 3 7 0.35 7
>   k n lam Q
> 1 4 8 0.4 8
>  k n  lam Q
> 1 5 9 0.45 9
>  k  n lam  Q
> 1 6 10 0.5 10
>  k  n  lam  Q
> 1 7 11 0.55 11
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@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.
>

        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to