在一个xts对象中的第N个日子 [英] Nth day of month in a xts object

查看:103
本文介绍了在一个xts对象中的第N个日子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

价格是一个xts对象

period.ends = endpoints(prices, 'months',k=1)

与这一行我找到一个月的最后一天的位置在一个时间序列。

with this line i find position of the last day of the month in a time series.

如何找到月的第一天的位置(不总是1个月)?第二天?

How to find position of the first day of month (not always 1 of the month)? And the second day?

谢谢

推荐答案

startpoints <- function (x, on = "months", k = 1) {
  head(endpoints(x, on, k) + 1, -1)
}

period.starts = startpoints(prices, 'months', k=1)

另请参见: xts ::: startof xts :: firstof

这篇关于在一个xts对象中的第N个日子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆