[R] Dataframe in loop

Ronaldo Reis Jr. chrysopa at insecta.ufv.br
Wed Mar 5 15:06:29 CET 2003


Hi,

I try to make a dataframe in a loop function, but I dont have succeed.

The function is something like this:

for(i in c(10,12)) {
   expr
      for(j in c(1:2) {
         total <- c(1,2,3,4,5,6,7)
         nspf <- length(levels(as.factor(total)))
         fin <- data.frame(L=i,N=nspf)
         print(fin)
  }
}

This print something like this:

   L N
1 10 7
   L N
1 10 7
   L N
1 12 7
   L N
1 12 7

But I need this print like:
   L N
1 10 7
2 10 7
3 12 7
4 12 7

I try some function modification to this but dont work.

This is just an example, the real function is a little big.

Thanks
ROnaldo

-- 
Why, every one as they like; as the good woman said when she kissed her cow.
		-- Rabelais
--
|   // | \\   [*****************************][*******************]
|| ( õ   õ )  [Ronaldo Reis Júnior          ][PentiumIII-600     ]
|      V      [UFV/DBA-Entomologia          ][HD: 30 + 10 Gb     ]
||  /     \   [36571-000 Viçosa - MG        ][RAM: 128 Mb        ]
|  /(.''`.)\  [Fone: 31-3899-2532           ][Video: SiS620-8Mb  ]
||/(: :'  :)\ [chrysopa at insecta.ufv.br      ][Modem: Pctel-onboar]
|/ (`. `'` ) \[ICQ#: 5692561                ][Kernel: 2.4.18     ]
||  ( `-  )   [*****************************][*******************]
||| _/   \_Powered by GNU/Debian W/Sarge D+ || Lxuser#: 205366



More information about the R-help mailing list