[R] How can I avoid nested 'for' loops or quicken the process?

David Winsemius dwinsemius at comcast.net
Tue Dec 23 17:15:34 CET 2008


On Dec 23, 2008, at 10:56 AM, Brigid Mooney wrote:

> Thank you again for your help.
>
snip
>

> -------------
> With the 'apply' call, Results2 is of class list.
>
> Results2 <- apply(CombParam, 1, calcProfit, X, Y)
> -------------------------------------------------------------------------------------------------------
>
> How can I get convert Results2 from a list to a data frame like  
> Results?

Have you tried as.data.frame() on Results2? Each of its elements  
should have the proper structure.

You no longer have a reproducible example, but see this session clip:
 > lairq <- apply(airquality,1, function(x) x )
 > str(lairq)
  num [1:6, 1:153] 41 190 7.4 67 5 1 36 118 8 72 ...
  - attr(*, "dimnames")=List of 2
   ..$ : chr [1:6] "Ozone" "Solar.R" "Wind" "Temp" ...
   ..$ : NULL
 > is.data.frame(lairq)
[1] FALSE
 > is.data.frame(rbind(lairq))
[1] FALSE
 > is.data.frame( as.data.frame(lairq) )
-- 
David Winsemius



More information about the R-help mailing list