0

我是新来的。我只是浏览了一些问题,发现这段代码我不理解,可能对我有用....他们在 R 中下载了一个 IRanges 包,代码与间隔有关。

4

1 回答 1

0

有关更多信息,tapply请参阅 ?tapply。

这里使用cut而不是包 IRanges 的代码版本:

  idx <- seq(1, ncol(df), by=2)
     o1 <- lapply(idx, function(i) {  
     ## create grouping factor
     fac <- cut(df[,i],seq(0,max(df[i]),30),labels=F)
     fac[is.na(fac)] <- max(fac,na.rm=T)+1
     # compute the mean by interval
     mean=tapply(df[,i+1],fac, mean)
     # put the result in a data.frame
     fac=levels(as.factor(fac))
     d <- data.frame(mean=mean,fac=fac)
})

将此应用于此结构

[1]]
      mean fac
1 1.300000   1
2 1.450000   2
3 2.925000   3
4 1.700000   4
5 2.333333   5

[[2]]
      mean fac
1 2.500000   1
2 2.350000   2
3 1.516667   3

[[3]]
  mean fac
1 1.78   1
2 1.90   2
于 2013-03-05T03:32:14.737 回答