One solution is to create a list, then do.call.
Here is my environment:
> ls()
[1] "DailyPL100416" "DailyPL100419"
"DailyPL100420" "l" "ll"
"PLglobal" "Pos100415" "Pos100416"
"Pos100419" "Pos100420"
"position" "r"
[13] "result" "sel" "select"
"Trad100415"
"Trad100416" "Trad100419" "Trad100420"
"trade" "tt"
"w"
> l<-list(grep("DailyPL",ls(),value=T)) #create a list of
elements with
DailyPL in the name
> l
[[1]]
[1] "DailyPL100416" "DailyPL100419"
"DailyPL100420"
> DF<-do.call("rbind",l)
> DF
[,1] [,2] [,3]
[1,] "DailyPL100416" "DailyPL100419"
"DailyPL100420"
That's not what I want! I expect "DF" to be a data.frame binded by
row.
I suspect there is an issue with get() or assign(), or something like that.
Any help is appreciated.
> -----Original Message-----
> From: arnaud Gaboury [mailto:arnaud.gaboury at gmail.com]
> Sent: Monday, May 24, 2010 2:55 PM
> To: r-help at r-project.org
> Cc: 'arnaud Gaboury'
> Subject: writing function:loop and rbind
>
> Dear group,
>
> I have a function, let's call it myfun, wich give me a list of result:
> R1,R2,R3...
> There is a loop in this function to get my results. Here is the
> structure of
> my function:
>
> Myfun<-function()
>
> {
> For (i in X ){
>
> -----------instructions---------
>
> Ri
>
> {
> {
>
> All Results (R1,R2...) are Data.frame. As a final result (call it
> "Final"),
> I need to rbind all these dataframe. One solution could be to create
> another
> loop, but I think I can avoid it. How can I add a line like this :
> Final<-rbind(R1,R2...) using the i parameter? Another solution could
> may be
> to create a list of all my results, then apply rbind to the list?
>
> Any idea would be appreciated.
>
> TY in advance