[R] why doesn't ifelse work ?

2011-04-28 Thread eric
I have the following lines of code: ind - rollapply(GSPC, 200, mean) signal - ifelse(diff(ind, 5) 0 , 1 , -1) signal[is.na(signal)] - 0 I never get a value of -1 for signal even though I know diff(ind , 5) is less than zero frequently. It looks like when diff(ind , 5) is less than zero, signal

Re: [R] why doesn't ifelse work ?

2011-04-28 Thread Andrew Robinson
Hi Eric, tough to say. Please try to provide commented, minimal, self-contained, reproducible code. Cheers Andrew On Thu, Apr 28, 2011 at 06:46:16PM -0700, eric wrote: I have the following lines of code: ind - rollapply(GSPC, 200, mean) signal - ifelse(diff(ind, 5) 0 , 1 , -1)

Re: [R] why doesn't ifelse work ?

2011-04-28 Thread Dennis Murphy
Hi: It seems to work for me...here's a reproducible example. set.seed(2053) date - seq(as.Date('1990-01-01'), by = 'days', length = 5000) range(date) # [1] 1990-01-01 2003-09-09 date - sort(sample(date, 2000)) tdata - data.frame(date = date, GSPC = rpois(2000, 1000)) library(zoo) tdata2 - tdata

Re: [R] why doesn't ifelse work ?

2011-04-28 Thread eric
equire(quantmod) require(PerformanceAnalytics) rm(list=ls()) getSymbols(^GSPC, src=yahoo, from=1990-01-01, to=Sys.Date()) GSPC -na.omit(Ad(GSPC)) ind - rollapply(GSPC, 200, mean) signal - ifelse(diff(ind, 5) 0 , 1 , -1) signal[is.na(signal)] - 0 -- View this message in context:

Re: [R] why doesn't ifelse work ?

2011-04-28 Thread eric
from the console ... table(signal) signal 01 1286 3885 note there is no -1 value. This is consistent with what I see if if plot(signal). When I issue that statement from the console, I see signal vary between 0 and 1.0 but it never goes to - 1 -- View this message in context:

Re: [R] why doesn't ifelse work ?

2011-04-28 Thread David Winsemius
On Apr 28, 2011, at 10:28 PM, eric wrote: equire(quantmod) require(PerformanceAnalytics) rm(list=ls()) getSymbols(^GSPC, src=yahoo, from=1990-01-01, to=Sys.Date()) GSPC -na.omit(Ad(GSPC)) ind - rollapply(GSPC, 200, mean) signal - ifelse(diff(ind, 5) 0 , 1 , -1) signal[is.na(signal)] - 0

Re: [R] why doesn't ifelse work ?

2011-04-28 Thread Dennis Murphy
Hi: On Thu, Apr 28, 2011 at 7:28 PM, eric ericst...@aol.com wrote: equire(quantmod) require(PerformanceAnalytics) rm(list=ls()) # Could you please not do this in the middle of a code chunk? # Anyone who copies/pastes this into his/her session will lose everything # (s)he had been doing.

Re: [R] why doesn't ifelse work ?

2011-04-28 Thread Joshua Wiley
Hi Eric, On Thu, Apr 28, 2011 at 6:46 PM, eric ericst...@aol.com wrote: I have the following lines of code: ind - rollapply(GSPC, 200, mean) signal - ifelse(diff(ind, 5) 0 , 1 , -1) If you had looked at signal here, you would see that it is logical. signal[is.na(signal)] - 0 but this is

Re: [R] Why doesn't this work ?

2011-03-17 Thread Iain Gallagher
The first line of this reply is a definite candidate for the fortunes package! best i --- On Thu, 17/3/11, bill.venab...@csiro.au bill.venab...@csiro.au wrote: From: bill.venab...@csiro.au bill.venab...@csiro.au Subject: Re: [R] Why doesn't this work ? To: ericst...@aol.com, r-help@r

Re: [R] Why doesn't this work ?

2011-03-17 Thread Ted Harding
- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of eric Sent: Thursday, 17 March 2011 1:26 PM To: r-help@r-project.org Subject: [R] Why doesn't this work ? Why doesn't this work and is there a better way ? z -ifelse(t==1 || 2 || 3, 1,0) t -3 z [1

Re: [R] Why doesn't this work ?

2011-03-17 Thread Barry Rowlingson
On Thu, Mar 17, 2011 at 3:54 AM, bill.venab...@csiro.au wrote: It doesn't work (in R) because it is not written in R.  It's written in some other language that looks a bit like R. It parses in R, so I would say it was written in R. To paraphrase Obi-wan, it's just not the R you are looking

[R] Why doesn't this work ?

2011-03-16 Thread eric
Why doesn't this work and is there a better way ? z -ifelse(t==1 || 2 || 3, 1,0) t -3 z [1] 1 t -4 z [1] 1 trying to say ...if t == 1 or if t== 2 or if t ==3 then true, otherwise false -- View this message in context: http://r.789695.n4.nabble.com/Why-doesn-t-this-work-tp3383656p3383656.html

Re: [R] Why doesn't this work ?

2011-03-16 Thread Bill.Venables
] On Behalf Of eric Sent: Thursday, 17 March 2011 1:26 PM To: r-help@r-project.org Subject: [R] Why doesn't this work ? Why doesn't this work and is there a better way ? z -ifelse(t==1 || 2 || 3, 1,0) t -3 z [1] 1 t -4 z [1] 1 trying to say ...if t == 1 or if t== 2 or if t ==3 then true, otherwise

Re: [R] Why doesn't this work ?

2011-03-16 Thread Phil Spector
Eric - What you mean to say is t - 3 z - ifelse(t %in% c(1,2,3),1,0) z [1] 1 t - 4 z - ifelse(t %in% c(1,2,3),1,0) [1] 0 Expressions don't recalculate themselves when you change the value of a variable that they use. For that, you would need a function: makez = function(t)ifelse(t