R-matrix vector comparison

I would like to compare the elements of a matrix column with the corresponding vector column.

So for example

>ret TLT VTI 1995-01-20 -0.005649718 -0.004461441 1995-01-23 -0.002840909 0.002560820 1995-01-24 0.000000000 0.000000000 1995-01-25 0.005698006 0.003831418 1995-01-26 0.000000000 0.001908397 >compare.vec [1] -0.001 -0.002 

I want to compare each returned item in column 1 ret to -0.001 and find which one is less than -0.001. And vice versa, for the second column, comparing it with -0.002 and we find elements in the VTI volumn that are smaller than this.

I tried a subset, but it doesn't seem to be for a vector, but for a number. Do I need a column to loop for a column?

Thanks,

+4
source share
1 answer

All you have to do is:

 t(t(ret) < compare.vec) 

EDIT based on a comment from Arun.

+8
source

Source: https://habr.com/ru/post/1479976/


All Articles