Skip to content
Prev 11294 / 398502 Next

list to data frame by rows ...

I am not yet shutting up on this :)

Thanks for the suggestions ... problem is that the code was
given as an illustration, in reality do4split would do
some complicated magic calculations that yield several
interesting results of mixed type.
Peter Dalgaard BSA wrote:
The problem here is that the functionality gets pulled out of 
do4split which isnt really possible in the *real* situation.
Patrick Connolly wrote:
As mentioned above, its not possible to split up do4split into
several pieces without doing the same calculations over and over
again.

So I guess there is no way around doing it iteratively. I would have
thought that adding the rows iteratively to an empty data frame
would be the obvious approach, but I am unable to make an empty 
data frame:
data.frame(list(a=c(),b=c()))
Error in names<-.default(*tmp*, value = vnames) : 
        names attribute must be the same length as the vector

However, its possible to make an list with "0 rows":
ltmp<-list(a=c(),b=c())

for (s in splitted) {
  print(s)
  tmp <- do4split(s)
  for (i in 1:length(tmp)) {
    ltmp[[i]]<-c(ltmp[[i]],tmp[[i]])
  }  
}

I would be curious how efficient this is and what actually happens.
Will ltmp[[i]]<-c(ltmp[[i]],tmp[[i]]) just extend the column or
will the whole content be copied every time? 

The final step 
  as.data.frame(ltmp)
again has the problem that the character columns will be converted
to levels. But when a column has class AsIs it wont:
  data.frame(lapply(ltmp,I))

Johann
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._