[R] loop

jim holtman jholtman at gmail.com
Sun Sep 7 00:31:27 CEST 2008


I would suggest that you use a 'list' since it seems that the result
is more than a single value:


bbayes<-list()
for(i in 1:100) {
    xx<-t(X1_10)%*%X1_10
    xxmeno1<-solve(xx)
    V<-xxmeno1*i
    Vmeno1<-solve(V)
    tx<-t(X1_10)
    prpar<-solve(Vmeno1+xx)
    snpar<-tx%*%y
    bbayes[[i]]<-prpar%*%snpar
}



On Sat, Sep 6, 2008 at 9:29 AM, Davide Crapis <cradav at hotmail.it> wrote:
>
> I have to calculate a formula that gives me a ten components vector. I want
> to see how the components behave at varying the variable i.
> But when i run the following function:
>> bbayes<-c()
>> for(i in 1:100) {
> + xx<-t(X1_10)%*%X1_10
> + xxmeno1<-solve(xx)
> + V<-xxmeno1*i
> + Vmeno1<-solve(V)
> + tx<-t(X1_10)
> + prpar<-solve(Vmeno1+xx)
> + snpar<-tx%*%y
> + bbayes<-prpar%*%snpar
> + }
>
> it oly gives me the vector calculated with the last value of the sequence,
> in this case 100.
> Could you please suggest how to print all the 100 vectors calculated for i
> in 1:100.
>
> Thank you in advance.
>
> Davide Crapis
> --
> View this message in context: http://www.nabble.com/loop-tp19346683p19346683.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?



More information about the R-help mailing list