Skip to content
Prev 258382 / 398502 Next

why doesn't ifelse work ?

Hi:
On Thu, Apr 28, 2011 at 7:28 PM, eric <ericstrom at aol.com> wrote:
# 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.
ind returns what is effectively a matrix with six columns. If you do
the same with the differences,
?zoo? series from 1990-05-31 to 2010-12-03
  Data: num [1:5172, 1:6] -1.303 -1.248 -1.13 -1.003 -0.946 ...
 - attr(*, "dimnames")=List of 2
  ..$ : NULL
  ..$ : chr [1:6] "GSPC.Open" "GSPC.High" "GSPC.Low" "GSPC.Close" ...
  Index: Class 'Date'  num [1:5172] 7455 7456 7459 7460 7461 ...
GSPC.Open GSPC.High GSPC.Low GSPC.Close GSPC.Volume GSPC.Adjusted
1990-05-31  -1.30300  -1.24530 -1.26890   -1.24725      295150      -1.24725
1990-06-01  -1.24750  -1.16410 -1.18735   -1.12970      313100      -1.12970
1990-06-04  -1.12995  -1.04920 -1.05475   -1.00325      334950      -1.00325
1990-06-05  -1.00345  -0.96625 -0.97210   -0.94540      134750      -0.94540
1990-06-06  -0.94560  -0.94210 -0.91795   -0.92290     -448450      -0.92290
1990-06-07  -0.92295  -0.91270 -0.89700   -0.90335     -544200      -0.90335

This informs you why the ifelse() statement doesn't make sense.
Perhaps this is what you had in mind:
$GSPC.Open

  -1    1
1285 3887

$GSPC.High

  -1    1
1283 3889

$GSPC.Low

  -1    0    1
1284    1 3887

$GSPC.Close

  -1    1
1286 3886

$GSPC.Volume

  -1    0    1
1349    1 3822

$GSPC.Adjusted

  -1    1
1286 3886

## with
GSPC.Open GSPC.High GSPC.Low GSPC.Close GSPC.Volume GSPC.Adjusted
1990-05-31        -1        -1       -1         -1           1            -1
1990-06-01        -1        -1       -1         -1           1            -1
1990-06-04        -1        -1       -1         -1           1            -1
1990-06-05        -1        -1       -1         -1           1            -1
1990-06-06        -1        -1       -1         -1          -1            -1
1990-06-07        -1        -1       -1         -1          -1            -1
[1] 0
[1] 2

Thank you for providing a reproducible example.

HTH,
Dennis