Dear group, Here is my environment:> ls()[1] "DailyPL100419" "DailyPL100420" "DailyPL100421" "dd" "i" "l" "PLglobal" "Pos100416" "Pos100419" "Pos100420" "Pos100421" "position" [13] "result" "sel" "Trad100416" "Trad100419" "Trad100420" "Trad100421" "trade" With "sel" the following element : sel <- c("100419", "100420", "100421") "DailyPL100419" , "DailyPL100420","DailyPL100421" are all data frames with same columns names. I want to rbind them with this condition : for (i in sel[-1]) I have no idea how to write it. TY for any help
Hello,
Does this do what you are looking for?
############
output <- NULL
for(i in paste("DailyPL", sel, sep="")[-1]){
output <- rbind(output, get(i))
}
############
If you just want to rbind all the data frames, there are ways of doing
it without a loop too, but since you specifically asked with the
condition for(i in sep[-1]) I did it using a loop.
Best regards,
Josh
On Wed, Jun 2, 2010 at 7:24 AM, arnaud Gaboury <arnaud.gaboury at
gmail.com> wrote:> Dear group,
>
> Here is my environment:
>
>> ls()
> ?[1] "DailyPL100419" "DailyPL100420"
"DailyPL100421" "dd" ? ? ? ? ? ?"i"
> "l" ? ? ? ? ? ? "PLglobal" ? ? ?"Pos100416" ?
? "Pos100419" ? ? "Pos100420"
> "Pos100421" ? ? "position"
> [13] "result" ? ? ? ?"sel" ? ? ? ? ?
"Trad100416" ? ?"Trad100419"
> "Trad100420" ? ?"Trad100421" ? ?"trade"
>
> With "sel" the following element :
>
> sel <-
> c("100419", "100420", "100421")
>
>
> "DailyPL100419" ,
"DailyPL100420","DailyPL100421" are all data frames with
> same columns names. I want to rbind them with this condition :
>
>
> for (i in sel[-1])
>
> I have no idea how to write it.
>
> TY for any help
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
--
Joshua Wiley
Senior in Psychology
University of California, Riverside
http://www.joshuawiley.com/
Yes indeed I just want to rbind the data frames with numbers belonging to
"sel", and if possible, avoid a loop.
To be more precise, if sel[-1]<-c("100420", "100421"), I
look for a line which will give me this result :
>dd<-rbind(DailyPL100420,DailyPL100421)
> -----Original Message-----
> From: Joshua Wiley [mailto:jwiley.psych at gmail.com]
> Sent: Wednesday, June 02, 2010 4:48 PM
> To: arnaud Gaboury
> Cc: r-help at r-project.org
> Subject: Re: [R] bind select data frames
>
> Hello,
>
> Does this do what you are looking for?
>
> ############
> output <- NULL
> for(i in paste("DailyPL", sel, sep="")[-1]){
> output <- rbind(output, get(i))
> }
> ############
>
> If you just want to rbind all the data frames, there are ways of doing
> it without a loop too, but since you specifically asked with the
> condition for(i in sep[-1]) I did it using a loop.
>
> Best regards,
>
> Josh
>
>
> On Wed, Jun 2, 2010 at 7:24 AM, arnaud Gaboury
> <arnaud.gaboury at gmail.com> wrote:
> > Dear group,
> >
> > Here is my environment:
> >
> >> ls()
> > [1] "DailyPL100419" "DailyPL100420"
"DailyPL100421" "dd"
> "i"
> > "l" "PLglobal"
"Pos100416" "Pos100419"
> "Pos100420"
> > "Pos100421" "position"
> > [13] "result" "sel"
"Trad100416" "Trad100419"
> > "Trad100420" "Trad100421" "trade"
> >
> > With "sel" the following element :
> >
> > sel <-
> > c("100419", "100420", "100421")
> >
> >
> > "DailyPL100419" ,
"DailyPL100420","DailyPL100421" are all data frames
> with
> > same columns names. I want to rbind them with this condition :
> >
> >
> > for (i in sel[-1])
> >
> > I have no idea how to write it.
> >
> > TY for any help
> >
> > ______________________________________________
> > R-help at r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> >
>
>
>
> --
> Joshua Wiley
> Senior in Psychology
> University of California, Riverside
> http://www.joshuawiley.com/
I am working with something like this :
for (i in sel[-1]) {
dd<-data.frame(do.call(rbind,
mget(paste("DailyPL",i,sep=""),envir=.GlobalEnv)),row.names=NULL)
}
But the result is not good. In the case where sel[-1]<-c("100420",
"100421"), "dd" is only equal to "DailyPL100421"
> -----Original Message-----
> From: Joshua Wiley [mailto:jwiley.psych at gmail.com]
> Sent: Wednesday, June 02, 2010 4:48 PM
> To: arnaud Gaboury
> Cc: r-help at r-project.org
> Subject: Re: [R] bind select data frames
>
> Hello,
>
> Does this do what you are looking for?
>
> ############
> output <- NULL
> for(i in paste("DailyPL", sel, sep="")[-1]){
> output <- rbind(output, get(i))
> }
> ############
>
> If you just want to rbind all the data frames, there are ways of doing
> it without a loop too, but since you specifically asked with the
> condition for(i in sep[-1]) I did it using a loop.
>
> Best regards,
>
> Josh
>
>
> On Wed, Jun 2, 2010 at 7:24 AM, arnaud Gaboury
> <arnaud.gaboury at gmail.com> wrote:
> > Dear group,
> >
> > Here is my environment:
> >
> >> ls()
> > [1] "DailyPL100419" "DailyPL100420"
"DailyPL100421" "dd"
> "i"
> > "l" "PLglobal"
"Pos100416" "Pos100419"
> "Pos100420"
> > "Pos100421" "position"
> > [13] "result" "sel"
"Trad100416" "Trad100419"
> > "Trad100420" "Trad100421" "trade"
> >
> > With "sel" the following element :
> >
> > sel <-
> > c("100419", "100420", "100421")
> >
> >
> > "DailyPL100419" ,
"DailyPL100420","DailyPL100421" are all data frames
> with
> > same columns names. I want to rbind them with this condition :
> >
> >
> > for (i in sel[-1])
> >
> > I have no idea how to write it.
> >
> > TY for any help
> >
> > ______________________________________________
> > R-help at r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> >
>
>
>
> --
> Joshua Wiley
> Senior in Psychology
> University of California, Riverside
> http://www.joshuawiley.com/
This should do the trick:
dd <- do.call(rbind, mget(paste("DailyPL",sel[-1],
sep=""), envir=.GlobalEnv))
On Wed, Jun 2, 2010 at 8:06 AM, arnaud Gaboury <arnaud.gaboury at
gmail.com> wrote:> I am working with something like this :
>
> ?for (i in sel[-1]) ?{
> dd<-data.frame(do.call(rbind,
mget(paste("DailyPL",i,sep=""),envir=.GlobalEnv)),row.names=NULL)
>
> ? ? ? ? ? ? ? }
>
> But the result is not good. In the case where
sel[-1]<-c("100420", "100421"), "dd" is only
equal to "DailyPL100421"
>
>
>
>
>> -----Original Message-----
>> From: Joshua Wiley [mailto:jwiley.psych at gmail.com]
>> Sent: Wednesday, June 02, 2010 4:48 PM
>> To: arnaud Gaboury
>> Cc: r-help at r-project.org
>> Subject: Re: [R] bind select data frames
>>
>> Hello,
>>
>> Does this do what you are looking for?
>>
>> ############
>> output <- NULL
>> for(i in paste("DailyPL", sel, sep="")[-1]){
>> ? output <- rbind(output, get(i))
>> ? }
>> ############
>>
>> If you just want to rbind all the data frames, there are ways of doing
>> it without a loop too, but since you specifically asked with the
>> condition for(i in sep[-1]) I did it using a loop.
>>
>> Best regards,
>>
>> Josh
>>
>>
>> On Wed, Jun 2, 2010 at 7:24 AM, arnaud Gaboury
>> <arnaud.gaboury at gmail.com> wrote:
>> > Dear group,
>> >
>> > Here is my environment:
>> >
>> >> ls()
>> > ?[1] "DailyPL100419" "DailyPL100420"
"DailyPL100421" "dd"
>> ?"i"
>> > "l" ? ? ? ? ? ? "PLglobal" ? ?
?"Pos100416" ? ? "Pos100419"
>> "Pos100420"
>> > "Pos100421" ? ? "position"
>> > [13] "result" ? ? ? ?"sel" ? ? ? ? ?
"Trad100416" ? ?"Trad100419"
>> > "Trad100420" ? ?"Trad100421" ?
?"trade"
>> >
>> > With "sel" the following element :
>> >
>> > sel <-
>> > c("100419", "100420", "100421")
>> >
>> >
>> > "DailyPL100419" ,
"DailyPL100420","DailyPL100421" are all data frames
>> with
>> > same columns names. I want to rbind them with this condition :
>> >
>> >
>> > for (i in sel[-1])
>> >
>> > I have no idea how to write it.
>> >
>> > TY for any help
>> >
>> > ______________________________________________
>> > R-help at r-project.org mailing list
>> > https://stat.ethz.ch/mailman/listinfo/r-help
>> > PLEASE do read the posting guide http://www.R-project.org/posting-
>> guide.html
>> > and provide commented, minimal, self-contained, reproducible code.
>> >
>>
>>
>>
>> --
>> Joshua Wiley
>> Senior in Psychology
>> University of California, Riverside
>> http://www.joshuawiley.com/
>
>
--
Joshua Wiley
Senior in Psychology
University of California, Riverside
http://www.joshuawiley.com/
Hi Arnaud,
Try the following (untested):
txt <- paste('DailyPL',c("100419", "100420",
"100421"), sep = "")
do.call(rbind, lapply(txt, get))
HTH,
Jorge
On Wed, Jun 2, 2010 at 10:24 AM, arnaud Gaboury <> wrote:
> Dear group,
>
> Here is my environment:
>
> > ls()
> [1] "DailyPL100419" "DailyPL100420"
"DailyPL100421" "dd" "i"
> "l" "PLglobal" "Pos100416"
"Pos100419" "Pos100420"
> "Pos100421" "position"
> [13] "result" "sel"
"Trad100416" "Trad100419"
> "Trad100420" "Trad100421" "trade"
>
> With "sel" the following element :
>
> sel <-
> c("100419", "100420", "100421")
>
>
> "DailyPL100419" ,
"DailyPL100420","DailyPL100421" are all data frames with
> same columns names. I want to rbind them with this condition :
>
>
> for (i in sel[-1])
>
> I have no idea how to write it.
>
> TY for any help
>
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
[[alternative HTML version deleted]]
On Wed, Jun 2, 2010 at 8:06 AM, arnaud Gaboury <arnaud.gaboury at gmail.com> wrote:> I am working with something like this : > > ?for (i in sel[-1]) ?{ > dd<-data.frame(do.call(rbind, mget(paste("DailyPL",i,sep=""),envir=.GlobalEnv)),row.names=NULL) > > ? ? ? ? ? ? ? } > > But the result is not good. In the case where sel[-1]<-c("100420", "100421"), "dd" is only equal to "DailyPL100421"Yes, because it is in a loop, dd is reassigned for each value of i. That is why in the first loop I sent you I included the old data in the rbind, otherwise it is just overwritten everytime it loops. Josh> > > > >> -----Original Message----- >> From: Joshua Wiley [mailto:jwiley.psych at gmail.com] >> Sent: Wednesday, June 02, 2010 4:48 PM >> To: arnaud Gaboury >> Cc: r-help at r-project.org >> Subject: Re: [R] bind select data frames >> >> Hello, >> >> Does this do what you are looking for? >> >> ############ >> output <- NULL >> for(i in paste("DailyPL", sel, sep="")[-1]){ >> ? output <- rbind(output, get(i)) >> ? } >> ############ >> >> If you just want to rbind all the data frames, there are ways of doing >> it without a loop too, but since you specifically asked with the >> condition for(i in sep[-1]) I did it using a loop. >> >> Best regards, >> >> Josh >> >> >> On Wed, Jun 2, 2010 at 7:24 AM, arnaud Gaboury >> <arnaud.gaboury at gmail.com> wrote: >> > Dear group, >> > >> > Here is my environment: >> > >> >> ls() >> > ?[1] "DailyPL100419" "DailyPL100420" "DailyPL100421" "dd" >> ?"i" >> > "l" ? ? ? ? ? ? "PLglobal" ? ? ?"Pos100416" ? ? "Pos100419" >> "Pos100420" >> > "Pos100421" ? ? "position" >> > [13] "result" ? ? ? ?"sel" ? ? ? ? ? "Trad100416" ? ?"Trad100419" >> > "Trad100420" ? ?"Trad100421" ? ?"trade" >> > >> > With "sel" the following element : >> > >> > sel <- >> > c("100419", "100420", "100421") >> > >> > >> > "DailyPL100419" , "DailyPL100420","DailyPL100421" are all data frames >> with >> > same columns names. I want to rbind them with this condition : >> > >> > >> > for (i in sel[-1]) >> > >> > I have no idea how to write it. >> > >> > TY for any help >> > >> > ______________________________________________ >> > R-help at r-project.org mailing list >> > https://stat.ethz.ch/mailman/listinfo/r-help >> > PLEASE do read the posting guide http://www.R-project.org/posting- >> guide.html >> > and provide commented, minimal, self-contained, reproducible code. >> > >> >> >> >> -- >> Joshua Wiley >> Senior in Psychology >> University of California, Riverside >> http://www.joshuawiley.com/ > >-- Joshua Wiley Senior in Psychology University of California, Riverside http://www.joshuawiley.com/
Yes Joshua, it does the trick. Once more, I am surprised by the easiness and
obviousness of R.
Now, I would like to add argument row.names=NULL.
dd <- do.call(rbind, mget(paste("DailyPL",sel[-1],
sep=""),
envir=.GlobalEnv),row.names=NULL)> Error in do.call(rbind, mget(paste("DailyPL", sel[-1], sep =
""), envir = .GlobalEnv), :
unused argument(s) (row.names = NULL)
Why this error?
TY for your help
> -----Original Message-----
> From: Joshua Wiley [mailto:jwiley.psych at gmail.com]
> Sent: Wednesday, June 02, 2010 5:08 PM
> To: arnaud Gaboury
> Cc: r-help at r-project.org
> Subject: Re: [R] bind select data frames
>
> This should do the trick:
>
> dd <- do.call(rbind, mget(paste("DailyPL",sel[-1],
sep=""),
> envir=.GlobalEnv))
>
>
>
> On Wed, Jun 2, 2010 at 8:06 AM, arnaud Gaboury
> <arnaud.gaboury at gmail.com> wrote:
> > I am working with something like this :
> >
> > for (i in sel[-1]) {
> > dd<-data.frame(do.call(rbind,
>
mget(paste("DailyPL",i,sep=""),envir=.GlobalEnv)),row.names=NULL)
> >
> > }
> >
> > But the result is not good. In the case where
sel[-1]<-c("100420",
> "100421"), "dd" is only equal to
"DailyPL100421"
> >
> >
> >
> >
> >> -----Original Message-----
> >> From: Joshua Wiley [mailto:jwiley.psych at gmail.com]
> >> Sent: Wednesday, June 02, 2010 4:48 PM
> >> To: arnaud Gaboury
> >> Cc: r-help at r-project.org
> >> Subject: Re: [R] bind select data frames
> >>
> >> Hello,
> >>
> >> Does this do what you are looking for?
> >>
> >> ############
> >> output <- NULL
> >> for(i in paste("DailyPL", sel, sep="")[-1]){
> >> output <- rbind(output, get(i))
> >> }
> >> ############
> >>
> >> If you just want to rbind all the data frames, there are ways of
> doing
> >> it without a loop too, but since you specifically asked with the
> >> condition for(i in sep[-1]) I did it using a loop.
> >>
> >> Best regards,
> >>
> >> Josh
> >>
> >>
> >> On Wed, Jun 2, 2010 at 7:24 AM, arnaud Gaboury
> >> <arnaud.gaboury at gmail.com> wrote:
> >> > Dear group,
> >> >
> >> > Here is my environment:
> >> >
> >> >> ls()
> >> > [1] "DailyPL100419" "DailyPL100420"
"DailyPL100421" "dd"
> >> "i"
> >> > "l" "PLglobal"
"Pos100416" "Pos100419"
> >> "Pos100420"
> >> > "Pos100421" "position"
> >> > [13] "result" "sel"
"Trad100416" "Trad100419"
> >> > "Trad100420" "Trad100421"
"trade"
> >> >
> >> > With "sel" the following element :
> >> >
> >> > sel <-
> >> > c("100419", "100420", "100421")
> >> >
> >> >
> >> > "DailyPL100419" ,
"DailyPL100420","DailyPL100421" are all data
> frames
> >> with
> >> > same columns names. I want to rbind them with this condition
:
> >> >
> >> >
> >> > for (i in sel[-1])
> >> >
> >> > I have no idea how to write it.
> >> >
> >> > TY for any help
> >> >
> >> > ______________________________________________
> >> > R-help at r-project.org mailing list
> >> > https://stat.ethz.ch/mailman/listinfo/r-help
> >> > PLEASE do read the posting guide
http://www.R-project.org/posting-
> >> guide.html
> >> > and provide commented, minimal, self-contained, reproducible
code.
> >> >
> >>
> >>
> >>
> >> --
> >> Joshua Wiley
> >> Senior in Psychology
> >> University of California, Riverside
> >> http://www.joshuawiley.com/
> >
> >
>
>
>
> --
> Joshua Wiley
> Senior in Psychology
> University of California, Riverside
> http://www.joshuawiley.com/
Here we go :
dd<-data.frame(do.call(rbind,
mget(paste("DailyPL",sel[-1],sep=""),envir=.GlobalEnv)),row.names=NULL)
TY so much Joshua and Jorge.
> -----Original Message-----
> From: Joshua Wiley [mailto:jwiley.psych at gmail.com]
> Sent: Wednesday, June 02, 2010 5:11 PM
> To: arnaud Gaboury
> Cc: r-help at r-project.org
> Subject: Re: [R] bind select data frames
>
> On Wed, Jun 2, 2010 at 8:06 AM, arnaud Gaboury
> <arnaud.gaboury at gmail.com> wrote:
> > I am working with something like this :
> >
> > for (i in sel[-1]) {
> > dd<-data.frame(do.call(rbind,
>
mget(paste("DailyPL",i,sep=""),envir=.GlobalEnv)),row.names=NULL)
> >
> > }
> >
> > But the result is not good. In the case where
sel[-1]<-c("100420",
> "100421"), "dd" is only equal to
"DailyPL100421"
>
> Yes, because it is in a loop, dd is reassigned for each value of i.
> That is why in the first loop I sent you I included the old data in
> the rbind, otherwise it is just overwritten everytime it loops.
>
> Josh
>
> >
> >
> >
> >
> >> -----Original Message-----
> >> From: Joshua Wiley [mailto:jwiley.psych at gmail.com]
> >> Sent: Wednesday, June 02, 2010 4:48 PM
> >> To: arnaud Gaboury
> >> Cc: r-help at r-project.org
> >> Subject: Re: [R] bind select data frames
> >>
> >> Hello,
> >>
> >> Does this do what you are looking for?
> >>
> >> ############
> >> output <- NULL
> >> for(i in paste("DailyPL", sel, sep="")[-1]){
> >> output <- rbind(output, get(i))
> >> }
> >> ############
> >>
> >> If you just want to rbind all the data frames, there are ways of
> doing
> >> it without a loop too, but since you specifically asked with the
> >> condition for(i in sep[-1]) I did it using a loop.
> >>
> >> Best regards,
> >>
> >> Josh
> >>
> >>
> >> On Wed, Jun 2, 2010 at 7:24 AM, arnaud Gaboury
> >> <arnaud.gaboury at gmail.com> wrote:
> >> > Dear group,
> >> >
> >> > Here is my environment:
> >> >
> >> >> ls()
> >> > [1] "DailyPL100419" "DailyPL100420"
"DailyPL100421" "dd"
> >> "i"
> >> > "l" "PLglobal"
"Pos100416" "Pos100419"
> >> "Pos100420"
> >> > "Pos100421" "position"
> >> > [13] "result" "sel"
"Trad100416" "Trad100419"
> >> > "Trad100420" "Trad100421"
"trade"
> >> >
> >> > With "sel" the following element :
> >> >
> >> > sel <-
> >> > c("100419", "100420", "100421")
> >> >
> >> >
> >> > "DailyPL100419" ,
"DailyPL100420","DailyPL100421" are all data
> frames
> >> with
> >> > same columns names. I want to rbind them with this condition
:
> >> >
> >> >
> >> > for (i in sel[-1])
> >> >
> >> > I have no idea how to write it.
> >> >
> >> > TY for any help
> >> >
> >> > ______________________________________________
> >> > R-help at r-project.org mailing list
> >> > https://stat.ethz.ch/mailman/listinfo/r-help
> >> > PLEASE do read the posting guide
http://www.R-project.org/posting-
> >> guide.html
> >> > and provide commented, minimal, self-contained, reproducible
code.
> >> >
> >>
> >>
> >>
> >> --
> >> Joshua Wiley
> >> Senior in Psychology
> >> University of California, Riverside
> >> http://www.joshuawiley.com/
> >
> >
>
>
>
> --
> Joshua Wiley
> Senior in Psychology
> University of California, Riverside
> http://www.joshuawiley.com/