r - 是否有 R 函数可以将时间序列格式化为数字的百分比?
问题描述
我有大量以百分比格式表示的兴趣时间序列。我需要将时间序列格式化为数字(百分比除以 100)而不是百分比。有这样做的功能吗?
我的时间序列:
NBdata10YS=xts(x=NBdata10YS$OBS_VALUE,order.by = as.Date(as.yearmon(NBdata10YS$TIME_PERIOD)))
NBdata5YS=xts(x=NBdata5YS$OBS_VALUE,order.by = as.Date(as.yearmon(NBdata5YS$TIME_PERIOD)))
NBdata3YS=xts(x=NBdata3YS$OBS_VALUE,order.by = as.Date(as.yearmon(NBdata3YS$TIME_PERIOD)))
StatsobligasjonerNB=merge(NBdata10YS,NBdata5YS, NBdata3YS)
数据。
NBdata3YS <-
structure(c(6.03, 5.65, 5.94, 6.19, 6.03, 5.95,
5.95, 6.06, 5.89, 5.75, 5.72, 5.5, 5.33, 5.29,
5.28, 5.33, 5.5, 5.47, 5.4, 5.47 ), class = c("xts",
"zoo"), .indexCLASS = "Date", tclass = "Date",
.indexTZ = "UTC", tzone = "UTC", index =
structure(c(852076800, 854755200, 857174400, 859852800,
862444800, 865123200, 867715200, 870393600, 873072000,
875664000, 878342400, 880934400, 883612800, 886291200,
888710400, 891388800, 893980800, 896659200, 899251200,
901929600), tzone = "UTC", tclass = "Date"),
.Dim = c(20L, 1L ))
解决方案
我不确定问题可能是什么。'zoo' 或 'xts' 类的对象实际上是具有特殊索引属性的数字矩阵。因此,只需使用除法运算符就足够了:
library(xts)
NBdata3YS/100
[,1]
1997-01-01 0.0603
1997-02-01 0.0565
1997-03-01 0.0594
1997-04-01 0.0619
1997-05-01 0.0603
1997-06-01 0.0595
1997-07-01 0.0595
1997-08-01 0.0606
1997-09-01 0.0589
1997-10-01 0.0575
1997-11-01 0.0572
1997-12-01 0.0550
1998-01-01 0.0533
1998-02-01 0.0529
1998-03-01 0.0528
1998-04-01 0.0533
1998-05-01 0.0550
1998-06-01 0.0547
1998-07-01 0.0540
1998-08-01 0.0547
这也适用于合并的 xts 时间序列:
M <- merge(NBdata3YS,NBdata3YS)
#-------------
> M/100
NBdata3YS NBdata3YS.1
1997-01-01 0.0603 0.0603
1997-02-01 0.0565 0.0565
1997-03-01 0.0594 0.0594
1997-04-01 0.0619 0.0619
1997-05-01 0.0603 0.0603
1997-06-01 0.0595 0.0595
1997-07-01 0.0595 0.0595
1997-08-01 0.0606 0.0606
1997-09-01 0.0589 0.0589
1997-10-01 0.0575 0.0575
1997-11-01 0.0572 0.0572
1997-12-01 0.0550 0.0550
1998-01-01 0.0533 0.0533
1998-02-01 0.0529 0.0529
1998-03-01 0.0528 0.0528
1998-04-01 0.0533 0.0533
1998-05-01 0.0550 0.0550
1998-06-01 0.0547 0.0547
1998-07-01 0.0540 0.0540
1998-08-01 0.0547 0.0547
推荐阅读
- bash - 如何通过 xargs 将多个查询参数传递到 httpie?
- c - 它是可移植的编译库吗?
- typescript - 确保对象将每个枚举值作为键(Typescript)?
- python - pip安装后找不到python模块
- python-3.x - 如何修复烧瓶中的'TypeError:'module'对象不可调用'?
- hugo - 如何在 Hugo 的 [permalinks] 部分中使用自定义参数?
- c# - 通过使用代理 API 将多个文件上传到 Sharepoint 2013 以验证文件上传过程(使用 vti_bin/copy.asmx)
- c++ - 我找不到在同一编译屏幕上与线程同时运行此计数器 3 次的方法
- java - Tomcat 8 Docx4j 应用程序问题
- bash - 给定字符串:approximateLastUseTime:'2019-10-15T16:56:07.082500Z',我需要提取 T 之后和 Z 之前的所有内容(冒号之后)