[R] which data structure to choose to keep multile objects?
jim holtman
jholtman at gmail.com
Sat Nov 7 13:59:12 CET 2009
your could try something like this:
xprocess<-function(max_val) {
result <- list()
for (iter in 2: max_val) {
zz = sprintf( "z%s", iter )
# use 'character' for indexing the list
result[[as.character(iter)]] <-nnmf(X,iter)
}
result
}
xprocess(10)
On Fri, Nov 6, 2009 at 6:58 PM, clue_less <suhai_tim_liu at yahoo.com> wrote:
>
> I have a function called nnmf which takes in one matrix and returns two
> matrices. for example,
>
>> X
> [,1] [,2] [,3] [,4]
> [1,] 1 4 7 10
> [2,] 2 5 8 11
> [3,] 3 6 9 12
>
>> z=nnmf(X,2)
>
>> z$W
> [,1] [,2]
> [1,] 0.8645422 0.6643681
> [2,] 1.7411863 0.5377504
> [3,] 2.6179287 0.4111063
>> z$H
> [,1] [,2] [,3] [,4]
> [1,] 1.14299486 1.692260 2.241279 2.79030
> [2,] 0.01838514 3.818559 7.619719 11.42087
>
> ----------------------------------------
>
> Now I would like to run it many times --
>
> z2 = nnmf(X,2)
> z3 = nnmf(X,3)
> z4 = nnmf(X,4)
> z5 = nnmf(X,5)
> ...
>
> But I would like to do it automatically , something like -
>
> xprocess<-function(max_val) {
> for (iter in 2: max_val) {
>
> zz = sprintf( "z%s", iter )
>
> zz <-nnmf(X,iter)
>
> }
>
> }
>
> xprocess(10)
>
>
> ----
>
> But how could I keep collection of my results each run?
>
> Shall I have a data structure to keep appending results?
>
> something like
>
> theta = {}
>
> ?
>
> which data structure to choose to keep multile objects?
>
> Thanks!
>
> Tim
>
> --
> View this message in context: http://old.nabble.com/which-data-structure-to-choose-to-keep-multile-objects--tp26231601p26231601.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