同じコードを実行します。なぜ編集しているのby=3
ですか?を作成しますidx = 1, 3, 5 ...
。by=3
、 を作成します1, 4, 7...
。あなたのデータは、フォーマットである限り、同じコードTime, data, Time, data, Time, data, ..., ...
を使用できます
require(IRanges)
# by equals 2 because we want to get the `Time` column index every time
idx <- seq(1, ncol(data), by=2)
# idx is now 1, 3, 5. It will be passed one value at a time to `i`.
# that is, `i` will take values 1 first, then 3 and then 5 and each time
# the code within is executed.
o <- lapply(idx, function(i) {
ir1 <- IRanges(start=seq(0, max(data[[i]]), by=401), width=401)
ir2 <- IRanges(start=data[[i]], width=1)
t <- findOverlaps(ir1, ir2)
d <- data.frame(mean=tapply(data[[i+1]], queryHits(t), mean))
cbind(as.data.frame(ir1), d)
})
このデータについて私に与えます:
# > o
# [[1]]
# start end width mean
# 1 0 400 401 1.05
#
# [[2]]
# start end width mean
# 1 0 400 401 1.1
#
# [[3]]
# start end width mean
# 1 0 400 401 1.383333