阅读背景:

如何分析R中数据集中信号(1和0)的连续持续性?

来源:互联网 

Let's say we have a data set that reflects a series of binary signals--either "1" or "0" over some time period. The goal is to measure the consecutive instances of 1, and sum the total. So, for instance, if 1 occurred four times in a row, the cumulative signal would be 4 for the fourth time period. If the next period--the fifth period--was 0, the counter resets until/if the 1 signal returns. I'm looking for a way to record the equivalent of rolling frequencies of consecutive instances of 1s. I've tried for loops and apply(), but can't seem to find the right mix. Any suggestions would be greatly appreciated. As a test, let's create some fake data. Any ideas on how to use R to solve this question? Thanks!Let's say we have a data set that reflects a se




你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: