Grokbase Groups R r-help March 2002
FAQ
I have to store a number of vectors of the same length. I know the
length but I do not know the number of vectors.

How can I store them as they are created (they are created one by one)?
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._

Search Discussions

  • Uwe Ligges at Mar 19, 2002 at 7:38 am

    Francisco J Molina wrote:
    I have to store a number of vectors of the same length. I know the
    length but I do not know the number of vectors.

    How can I store them as they are created (they are created one by one)?
    *Please* read "An Introduction to R"!

    rbind() and indexing a matrix M[i, j] are possible solutions.

    Uwe Ligges
    -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
    r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
    Send "info", "help", or "[un]subscribe"
    (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
    _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
  • Sven Garbade at Mar 19, 2002 at 9:06 am

    Francisco J Molina wrote:

    I have to store a number of vectors of the same length. I know the
    length but I do not know the number of vectors.

    How can I store them as they are created (they are created one by one)?
    Maybe

    data <- vector(mode="numeric")
    # and here functions, loops or whatever to read the data
    newdata <- datafromanywhere
    data <- rbind(data, newdata)

    Regards, Sven




    -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
    r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
    Send "info", "help", or "[un]subscribe"
    (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
    _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
  • Agustin Lobo at Mar 19, 2002 at 9:24 am
    If the vectors are created within a loop,

    matriz <- NULL
    for(...){
    ...
    matriz <- cbind(matriz,vector)
    }
    matriz

    but I think that it's better to define matriz with a large
    number of cols and avoid growing the matrix within the
    loop:

    matriz <- matrix(NULL,nrow=numlineas,ncol=maxnumcols)
    col <- 0
    for(...){
    col <- col+1
    ...
    matriz[,col] <- vector
    }
    matriz <- matriz[,1:col] #keep only the used cols
    matriz

    ..and even better if you can avoid the loop, R offers
    many opportunities for that.



    Dr. Agustin Lobo
    Instituto de Ciencias de la Tierra (CSIC)
    Lluis Sole Sabaris s/n
    08028 Barcelona SPAIN
    tel 34 93409 5410
    fax 34 93411 0012
    alobo at ija.csic.es

    On Mon, 18 Mar 2002, Francisco J Molina wrote:

    I have to store a number of vectors of the same length. I know the
    length but I do not know the number of vectors.

    How can I store them as they are created (they are created one by one)?
    -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
    r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
    Send "info", "help", or "[un]subscribe"
    (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
    _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
    -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
    r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
    Send "info", "help", or "[un]subscribe"
    (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
    _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
  • Agustin Lobo at Mar 19, 2002 at 11:48 am

    On Tue, 19 Mar 2002, Agustin Lobo wrote:

    matriz <- matrix(NULL,nrow=numlineas,ncol=maxnumcols)
    Actually I had not tried it, it should be, i.e.

    matriz <- matrix(0,nrow=numlineas,ncol=maxnumcols)

    as with NULL we cannot fill a matrix

    Agus


    -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
    r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
    Send "info", "help", or "[un]subscribe"
    (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
    _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
  • E. D. Isaia at Mar 28, 2002 at 6:35 am
    Is that you mean?

    X<-cbind(c(10,12,13,11),c(20,25,24,22),c(50,45,54,58))
    dim(X)
    [1] 4 3

    Best, isaia.

    Francisco J Molina wrote:
    I have to store a number of vectors of the same length. I know the
    length but I do not know the number of vectors.

    How can I store them as they are created (they are created one by one)?
    -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
    r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
    Send "info", "help", or "[un]subscribe"
    (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
    _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
    --
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ~ Ennio D. Isaia
    ~ Dep. of Statistics & Mathematics, University of Torino
    ~ Piazza Arbarello, 8 - 10128 Torino (Italy)
    ~ Phone: +39 011 670 62 51 ~~ Fax: +39 011 670 62 39
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


    -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
    r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
    Send "info", "help", or "[un]subscribe"
    (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
    _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupr-help @
categoriesr
postedMar 19, '02 at 3:08a
activeMar 28, '02 at 6:35a
posts6
users5
websiter-project.org
irc#r

People

Translate

site design / logo © 2017 Grokbase