[R] Condition warning: has length 1 and only the first element will be used

2008-10-15 Thread Joe Kaser
Hello, I've been learning R functions recently and I've come across a problem that perhaps someone could help me with. # I have a a chron() object of times hours=chron(time=c(01:00:00,18:00:00,13:00:00,10:00:00)) # I would like to subtract 12 hours from each time element, so I created a

Re: [R] Condition warning: has length 1 and only the first element will be used

2008-10-15 Thread Greg Snow
The if statement is for program flow control (do this bunch of code if this condition is true, else do this), the vectorized version is the ifelse function, that is the one that you want to use. Also note (this is for times in general, not sure about chron specifically) subtracting noon from

Re: [R] Condition warning: has length 1 and only the first element will be used

2008-10-15 Thread Peter Dalgaard
Joe Kaser wrote: Hello, I've been learning R functions recently and I've come across a problem that perhaps someone could help me with. # I have a a chron() object of times hours=chron(time=c(01:00:00,18:00:00,13:00:00,10:00:00)) # I would like to subtract 12 hours from each time element,

Re: [R] Condition warning: has length 1 and only the first element will be used

2008-10-15 Thread Joe Kaser
Thanks for the help. ifelse does the job. Could you elaborate, or give an example of the awkward things ifelse might do to classed objects? On Wed, Oct 15, 2008 at 1:38 PM, Peter Dalgaard [EMAIL PROTECTED]wrote: Joe Kaser wrote: Hello, I've been learning R functions recently and I've come

Re: [R] Condition warning: has length 1 and only the first element will be used

2008-10-15 Thread Joe Kaser
Ah! Thanks. ifelse() appears to do the job. note: subtracting 12 from chron rather than noon doesn't seem to work. I think (but am not totally sure) chron interprets 12 as fraction of a day - i.e. 12/1 days... On Wed, Oct 15, 2008 at 1:33 PM, Greg Snow [EMAIL PROTECTED] wrote: The if

Re: [R] Condition warning: has length 1 and only the first element will be used

2008-10-15 Thread Peter Dalgaard
Joe Kaser wrote: Thanks for the help. ifelse does the job. Could you elaborate, or give an example of the awkward things ifelse might do to classed objects? It strips the class. One thing that usually gets me is this: dd - as.Date(c(2008-1-2,2007-3-21))