简体   繁体   English

有人可以解释端点 function 的工作原理吗?

[英]Can someone explain how endpoints function works?

I don't understand why I receive an output from endpoints function, whereas I am expecting something else.我不明白为什么我会从端点 function 收到 output,而我期待别的东西。 I wrote a pseudo code, could someone explain the mechanism?我写了一个伪代码,有人可以解释一下机制吗?

y1<-rep(1,times=750)
y1<-xts(y1, order.by = Sys.Date()-1:750)
endpoints(y1,'days',250)

With this code R returns 0 123 347 484 713 750 .使用此代码 R 返回0 123 347 484 713 750 Shouldn't it return 250 500 750 ?它不应该返回250 500 750吗? Or how would it return those indices?或者它将如何返回这些索引? Thanks谢谢

Looks like endpoints always generates a point at the end of the year and that k is counted from the beginning of the year on:看起来endpoints总是在年底生成一个点,并且k从年初开始计算:

y1[endpoints(y1,'days',k=250)]
           [,1]
2019-09-07    1
2019-12-31    1
2020-09-06    1
2020-12-31    1
2021-02-06    1

Above result is either 250th day of year or end of year.以上结果是一年中的第 250 天或年末。
Didn't find an explicit mention to this in documentation, but source code shows that year plays a key role even if counting days :在文档中没有明确提到这一点,但源代码显示即使计算days数, year也起着关键作用:


days = {
    ixyday <- posixltindex$year * 1000L + 1900000L + posixltindex$yday
    .Call("endpoints", ixyday, 1L, k, addlast, PACKAGE = "xts")
  }

To get the indexes you are looking for, you could use %% (modulo operator):要获取您正在寻找的索引,您可以使用%% (模运算符):

which(1:750%%250==0)
[1] 250 500 750

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 有人可以解释在 data.table 中执行更新时,mult 是如何工作的吗(使用 .EACHI 和 mult) - Can someone explain how mult works in data.table when it performs update in joins (using .EACHI and mult) 有人可以解释R中pvclust函数的输出吗? - Can someone explain the output from the pvclust function in R? 当我使用相对引用时,有人可以在R的semi_join函数中解释“意外的&#39;=”消息吗? - Can someone explain the 'unexpected '='' message in my semi_join function in R when I use relative references? 有人可以解释我这段代码吗? 特别是“函数x和[[x]]”的作用? - Can someone please explain me this code? especially the role of "function x and [[x]]"? r:有人可以向我解释这个 dplyr 代码吗? - r: can someone explain this dplyr code to me? 有人可以解释 R 的底层方法吗? - Can someone explain the underlying methods of R? 有人可以解释R中`&lt;&lt;-`赋值运算符的行为吗? - Can someone explain the behaviour of `<<-` assignament operator in R? 有人可以解释这些代码行的含义吗? - Can someone explain what these lines of code mean? 有人可以解释 R 软件中 %in% 的 arguments 的顺序吗? - Can someone explain the order of arguments for %in% in R software? 有人可以解释这段代码在做什么吗? - Can someone explain what this code is doing?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM