Dear group, Here is my environment :> ls()[1] "l" "PLglobal" "Pos100415" "Pos100416" "Pos100419" "Pos100420" "position" "select" "Trad100415" "Trad100416" "Trad100419" "Trad100420" "trade" "y" With objects :> l[1] "100415" "100416" "100419" "100420" "100421" "100422" "100423" "100426" "100427" "100428" "100429" "100430" "100503" "100504" "100505" "100506" "100507" "100510" "100511" "100512" "100513"> select #is a selection of elements of object "l"[1] "100415" "100416" "100419" "100420" "PLglobal", "position", "trade" are all functions Pos100415,Pos100416,Trad100415...are all data frames I have one dataframe each day. For example, Pos100415 is "Pos" for day 15/04/2010. Now I need to access data.frames in my environment for a function, according to this following scheme: Pos100415 and Pos100416 (i.e. Pos(day1) and Pos(day2)), and Trad100416 (i.e. trad(day2)). I have absolutely no idea how to deal with this indexing problem in a generic manner. Note that all numbers will belong to the list "select". Not sur to be clear enough, but any help would be appreciated. TY
Dear R-users, I've been trying to write a script but i encounter much problems with basic functions.. That is, i try to write a simple IF ELSE statement, with 2 requirements for the IF : if (abs(x + Dataset$LAT[1]) <= 3) and (abs(y + Dataset$LONG[1]) <= 3) {z <- 1} else {z <-0} This does not work. So far i succeeded with one of tthe conditions : if (abs(x + Dataset$LAT[1]) <= 3) {z <- 1} else {z <-0}> this work, so i tried to had the second condition with "and" or"&" or even "& &&" as writen in operators r-help but none of my trials works, it retrun "unexpected symbol "{" ... any tip ? with regards [[alternative HTML version deleted]]
On May 21, 2010, at 9:19 AM, arnaud Gaboury wrote:> Dear group, > > Here is my environment : > >> ls() > [1] "l" "PLglobal" "Pos100415" "Pos100416" "Pos100419" > "Pos100420" "position" "select" "Trad100415" "Trad100416" > "Trad100419" "Trad100420" "trade" "y" > > With objects : > >> l > [1] "100415" "100416" "100419" "100420" "100421" "100422" "100423" > "100426" > "100427" "100428" "100429" "100430" "100503" "100504" "100505" > "100506" > "100507" "100510" "100511" "100512" "100513" > >> select #is a selection of elements of object "l" > [1] "100415" "100416" "100419" "100420" > > "PLglobal", "position", "trade" are all functions > Pos100415,Pos100416,Trad100415...are all data frames > > I have one dataframe each day. For example, Pos100415 is "Pos" for day > 15/04/2010. > > Now I need to access data.frames in my environment for a function, > according > to this following scheme: > > Pos100415 and Pos100416 (i.e. Pos(day1) and Pos(day2)), and > Trad100416 (i.e. > trad(day2)). > > I have absolutely no idea how to deal with this indexing problem in a > generic manner. Note that all numbers will belong to the list > "select".Sounds like you need to have one Positions dataframe and one Trades dataframe rather than leaving them separate. Then you would be indexing by day and if needed the subset function could parcel out particular day-defined subsets. I would not use the object name "select" since it is one of the argument names for subset. -- David Winsemius, MD West Hartford, CT
This maybe a solution. I am currently working with something like : For (i in length(select)){ posA<-get(paste(c("Pos",select[i]),collapse="")) posB<-get(paste(c("Pos",select[i+1]),collapse="")) } Not yet finalized. TY for the tip about "select" not to use as an object name> -----Original Message----- > From: David Winsemius [mailto:dwinsemius at comcast.net] > Sent: Friday, May 21, 2010 4:00 PM > To: arnaud Gaboury > Cc: r-help at r-project.org > Subject: Re: [R] indexing problem > > > On May 21, 2010, at 9:19 AM, arnaud Gaboury wrote: > > > Dear group, > > > > Here is my environment : > > > >> ls() > > [1] "l" "PLglobal" "Pos100415" "Pos100416" "Pos100419" > > "Pos100420" "position" "select" "Trad100415" "Trad100416" > > "Trad100419" "Trad100420" "trade" "y" > > > > With objects : > > > >> l > > [1] "100415" "100416" "100419" "100420" "100421" "100422" "100423" > > "100426" > > "100427" "100428" "100429" "100430" "100503" "100504" "100505" > > "100506" > > "100507" "100510" "100511" "100512" "100513" > > > >> select #is a selection of elements of object "l" > > [1] "100415" "100416" "100419" "100420" > > > > "PLglobal", "position", "trade" are all functions > > Pos100415,Pos100416,Trad100415...are all data frames > > > > I have one dataframe each day. For example, Pos100415 is "Pos" for > day > > 15/04/2010. > > > > Now I need to access data.frames in my environment for a function, > > according > > to this following scheme: > > > > Pos100415 and Pos100416 (i.e. Pos(day1) and Pos(day2)), and > > Trad100416 (i.e. > > trad(day2)). > > > > I have absolutely no idea how to deal with this indexing problem in a > > generic manner. Note that all numbers will belong to the list > > "select". > > Sounds like you need to have one Positions dataframe and one Trades > dataframe rather than leaving them separate. Then you would be > indexing by day and if needed the subset function could parcel out > particular day-defined subsets. I would not use the object name > "select" since it is one of the argument names for subset. > > -- > > David Winsemius, MD > West Hartford, CT
This do the trick : for (i in 1:length(sel) ){ posA<-get(paste(c("Pos",sel[i]),collapse="")) posB<-get(paste(c("Pos",sel[i]+1),collapse="")) }> -----Original Message----- > From: David Winsemius [mailto:dwinsemius at comcast.net] > Sent: Friday, May 21, 2010 4:00 PM > To: arnaud Gaboury > Cc: r-help at r-project.org > Subject: Re: [R] indexing problem > > > On May 21, 2010, at 9:19 AM, arnaud Gaboury wrote: > > > Dear group, > > > > Here is my environment : > > > >> ls() > > [1] "l" "PLglobal" "Pos100415" "Pos100416" "Pos100419" > > "Pos100420" "position" "select" "Trad100415" "Trad100416" > > "Trad100419" "Trad100420" "trade" "y" > > > > With objects : > > > >> l > > [1] "100415" "100416" "100419" "100420" "100421" "100422" "100423" > > "100426" > > "100427" "100428" "100429" "100430" "100503" "100504" "100505" > > "100506" > > "100507" "100510" "100511" "100512" "100513" > > > >> select #is a selection of elements of object "l" > > [1] "100415" "100416" "100419" "100420" > > > > "PLglobal", "position", "trade" are all functions > > Pos100415,Pos100416,Trad100415...are all data frames > > > > I have one dataframe each day. For example, Pos100415 is "Pos" for > day > > 15/04/2010. > > > > Now I need to access data.frames in my environment for a function, > > according > > to this following scheme: > > > > Pos100415 and Pos100416 (i.e. Pos(day1) and Pos(day2)), and > > Trad100416 (i.e. > > trad(day2)). > > > > I have absolutely no idea how to deal with this indexing problem in a > > generic manner. Note that all numbers will belong to the list > > "select". > > Sounds like you need to have one Positions dataframe and one Trades > dataframe rather than leaving them separate. Then you would be > indexing by day and if needed the subset function could parcel out > particular day-defined subsets. I would not use the object name > "select" since it is one of the argument names for subset. > > -- > > David Winsemius, MD > West Hartford, CT