[R] Data.frames with different line's length
Petr Pikal
petr.pikal at precheza.cz
Tue Jun 21 14:34:38 CEST 2005
Hi
from help page
Details:
A data frame is a list of variables of the same length with unique
^^^^^^^^^^
row names, given class '"data.frame"'.
So you need to use a different sructure (e.g.list) or you have to
ensure that you rbind vectors of same length.
HTH
Petr
On 21 Jun 2005 at 12:09, Joăo Mendes Moreira wrote:
> Hello,
>
> I want to create a data.frame with different number of columns per
> line. What I want is something like:
>
> example <- NULL
> begin <- 1
> while (end < nrow(orig.data))
> {
> end <- next.day(orig.data,begin) # my own function. It returns the
> first index from the next day. Each day has a different number of
> records. example <- rbind(example, c(begin, end,
> predictions[c(begin:end)], ...)) begin <- end+1 }
>
> It gives the following warning:
>
> > number of columns of result
> not a multiple of vector length (arg 2) in: rbind(example,
> c(begin, end, predictions[c(begin:end)], ...
>
> I believe this happen once the number of elements by line are
> different. The example data.frame repeats the same values for shorter
> lines until the line is full, i.e., it tries to create lines with the
> same number of columns.
>
> The question is: How can I create a data.frame with different number
> of columns?
>
> Any help is very much appreciated
>
> Thanks in advance
>
> Joao Moreira
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
Petr Pikal
petr.pikal at precheza.cz
More information about the R-help
mailing list