Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在R中绘制方波数据?_R - Fatal编程技术网

如何在R中绘制方波数据?

如何在R中绘制方波数据?,r,R,考虑以下数据,其中左列表示一个位(1或0),右列表示我们观察该位的微秒数 0 664 1 63 0 404 1 544 0 651 1 686 0 507 1 1155 0 664 1 271 0 456 1 2763 0 664 1 115 0 456 1 4010 0 664 1 63 0 351 1 3855 我想绘制这个数据,这样在0处有一条宽度为664的水平线,然后在1处上升到一条宽度为63的水平线,然后在0处下降到一条宽度为404的水平线,依此类推 是否有一种有效且直接的方法来绘制

考虑以下数据,其中左列表示一个位(1或0),右列表示我们观察该位的微秒数

0 664
1 63
0 404
1 544
0 651
1 686
0 507
1 1155
0 664
1 271
0 456
1 2763
0 664
1 115
0 456
1 4010
0 664
1 63
0 351
1 3855
我想绘制这个数据,这样在0处有一条宽度为664的水平线,然后在1处上升到一条宽度为63的水平线,然后在0处下降到一条宽度为404的水平线,依此类推

是否有一种有效且直接的方法来绘制R中的曲线,而不需要手动比较边界

这是我目前的代码,它非常低效和幼稚,所以我希望有更好的方法

args <- commandArgs(trailingOnly = TRUE)
data = read.table(args[1])
current = 1
sumA = 0

pf = function(x) {
    if (x < sumA) {
        return(data[current,1])
    }

    for (i in  current: length(data[,1])) {
        sumA <<- sumA + data[i,2]
        if (x < sumA) {
            current <<- i + 1
            return(data[i,1])
        }
    }
    return("OUT OF BOUNDS")
}
cumSum = colSums(data)[[2]]
print(cumSum - 1);


h = Vectorize(pf)
plot(h, 1, cumSum-1, n=cumSum-1, lwd=0.001, xlim=c(0,cumSum-1))

args正如我在评论中提到的,将
type
标志设置为
s
应该可以起到作用

例如,对于第一批
10
样本:

x <- c(0,664,63,404,544,651,686,507,1155,664,271)
xC <- cumsum(x)
y <- c(0,1,0,1,0,1,0,1,0,1,0)
plot(xC,y,type='s')

x应该是您感兴趣的。“这两种台阶类型的x-y偏好不同:从(x1,y1)到(x2,y2),x1