R 将矩阵除以一列

R 将矩阵除以一列,r,matrix,vectorization,xts,R,Matrix,Vectorization,Xts,我有一个多列xts,我想除以一个xts(当然,使用日期作为主键) 有没有办法以矢量化的方式实现这一点 谢谢参见?扫描(如果我理解你的意思-可复制的示例!?): data(sample_matrix) sample.xts <- as.xts(sample_matrix, descr='my new xts object') ## create a matrix... m <- sample.xts[, -1] ## ...and a vector from the sample.xt

我有一个多列xts,我想除以一个xts(当然,使用日期作为主键)

有没有办法以矢量化的方式实现这一点

谢谢

参见
?扫描
(如果我理解你的意思-可复制的示例!?):

data(sample_matrix)
sample.xts <- as.xts(sample_matrix, descr='my new xts object')
## create a matrix...
m <- sample.xts[, -1]
## ...and a vector from the sample.xts object
v <- sample.xts[, 1]
## apply sweep
out <- sweep(m, 1, v, "/")
> class(out)
[1] "xts" "zoo"
> head(out)
               High       Low     Close
2007-01-02 1.001559 0.9982141 1.0015587
2007-01-03 1.003810 1.0000000 1.0033281
2007-01-04 1.000000 0.9968898 0.9982428
2007-01-05 1.000000 0.9969739 0.9992283
2007-01-06 1.000000 0.9973506 0.9987421
2007-01-07 1.001666 0.9972022 0.9972022