Re: [R] Unexpected behavior looping through sequence of dates

2013-03-09 Thread Alexandre Sieira
Thanks for the clarification, Luke. That is really counter-intuitive behavior. I 100% agree with you that the "for" documentation should state that assumption explicitly. I would also like to suggest changing the "for" implementation to issue a warning if the "seq" argument is a vector of a

Re: [R] Unexpected behavior looping through sequence of dates

2013-03-09 Thread luke-tierney
On Sat, 9 Mar 2013, Alexandre Sieira wrote: Thanks for the clarification, Luke. That is really counter-intuitive behavior. I 100% agree with you that the "for" documentation should state that assumption explicitly. I would also like to suggest changing the "for" implementation to issue a warn

Re: [R] Unexpected behavior looping through sequence of dates

2013-03-09 Thread David Winsemius
On Mar 9, 2013, at 1:10 PM, wrote: > R's for loop is only designed to iterato over primitive types. The > help file says of the seq argument: > > seq: An expression evaluating to a vector (including a list and an > expression) or to a pairlist or ‘NULL’. A factor value will >

Re: [R] Unexpected behavior looping through sequence of dates

2013-03-09 Thread luke-tierney
R's for loop is only designed to iterato over primitive types. The help file says of the seq argument: seq: An expression evaluating to a vector (including a list and an expression) or to a pairlist or ‘NULL’. A factor value will be coerced to a character vector. [This

Re: [R] Unexpected behavior looping through sequence of dates

2013-03-09 Thread Peter Ehlers
On 2013-03-09 11:14, R. Michael Weylandt wrote: On Sat, Mar 9, 2013 at 6:50 PM, David Winsemius wrote: I was unable to find the reason for the original coercion in the help("for") page or the R Language Definition entry regarding for-loops. On the hunch that coercion via as.vector might be oc

Re: [R] Unexpected behavior looping through sequence of dates

2013-03-09 Thread R. Michael Weylandt
On Sat, Mar 9, 2013 at 6:50 PM, David Winsemius wrote: > I was unable to find the reason for the original coercion in the help("for") > page or the R > Language Definition entry regarding for-loops. On the hunch that coercion via > as.vector > might be occurring, Behaviorally, it seems to, but

Re: [R] Unexpected behavior looping through sequence of dates

2013-03-09 Thread David Winsemius
On Mar 9, 2013, at 9:24 AM, Alexandre Sieira wrote: > I understand that the two following loops should produce the exact same > output. However, they do not. It appears that looping directly through the > sequence of Date objects somehow makes them be coerced to numeric: > >> date1 = "20130301

[R] Unexpected behavior looping through sequence of dates

2013-03-09 Thread Alexandre Sieira
I understand that the two following loops should produce the exact same output. However, they do not. It appears that looping directly through the sequence of Date objects somehow makes them be coerced to numeric: > date1 = "20130301" > date2 = "20130302" > > d1 = as.Date(date1, format="%Y%m%d"