Or simply do :
position <- as.numeric(trend1 == trend2 )
position
2011/2/24 Dimitris Rizopoulos
> there are also vectorized logical operators; have a look at the help page
> ?'&', and try this:
>
>
> trend1 <- c(1,1,1,1,1,1,-1,-1,-1,-1,-1,-1)
> trend2 <- c(1,1,1,1,1,1,1,1,1,1,1,-1)
>
> position
Thanks all. This works..
On Thu, Feb 24, 2011 at 3:43 AM, Jim Lemon wrote:
> On 02/24/2011 08:37 PM, Dimitris Rizopoulos wrote:
>
>> there are also vectorized logical operators; have a look at the help
>> page ?'&', and try this:
>>
>> trend1 <- c(1,1,1,1,1,1,-1,-1,-1,-1,-1,-1)
>> trend2 <- c(1,
On 02/24/2011 08:43 PM, Jim Lemon wrote:
Oops, forgot about the zero!
trunc((trend1 * trend2 + 1)/2)
Jim
__
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/posti
On 02/24/2011 08:37 PM, Dimitris Rizopoulos wrote:
there are also vectorized logical operators; have a look at the help
page ?'&', and try this:
trend1 <- c(1,1,1,1,1,1,-1,-1,-1,-1,-1,-1)
trend2 <- c(1,1,1,1,1,1,1,1,1,1,1,-1)
position <- as.numeric((trend1 == 1 & trend2 == 1) | (trend1 == -1 &
Hi,
I think you want ifelse().
Assuming that length(trend2)=12 and not 14 as in the data you provided,
that should work:
position <- ifelse((trend1==1 & trend2==1)|(trend1==-1 &
trend2==-1),1,0) #btw, note the single "&" and single "|", not double
HTH,
Ivan
Le 2/24/2011 09:41, Kushan Thak
there are also vectorized logical operators; have a look at the help
page ?'&', and try this:
trend1 <- c(1,1,1,1,1,1,-1,-1,-1,-1,-1,-1)
trend2 <- c(1,1,1,1,1,1,1,1,1,1,1,-1)
position <- as.numeric((trend1 == 1 & trend2 == 1) | (trend1 == -1 &
trend2 == -1))
position
I hope it helps.
Best,
I have two vectors: both have possible values of 1,-1, or 0
trend1 <- c(1,1,1,1,1,1,-1,-1,-1,-1,-1,-1)
trend2 <- c(1,1,1,1,1,1,1,1,1,1,1,1,1,1,)
i want to create a third vector that is conditional upon these two vectors:
if (trend2 == 1 && trend1 == 1) {position <- 1}
elseif (trend2 == -1 && tre
7 matches
Mail list logo