R编程修复错误 [英] R programming fixing error

查看:158
本文介绍了R编程修复错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我问了一个与此类似的问题

Hi guys I asked a similar question about this here previously and I got some really awesome answers. But it turns out I have more data I need to work with sadly. So I have sample data in this format which is generated using head(data). So I have 3 specimens with their own Time and speed data....I'm not exactly using speed for my actual data

Time Speed Time.1 Speed.1 Time.2 Speed.2

Error in unique.default(x) : unique() applies only to vectors

你们可以告诉我该怎么做吗?我可以使用excel在公式中执行此操作,但是我有很多数据会导致excel崩溃,因此我确实需要'R',但对此却知之甚少...谢谢大家....

Would it be possible for you guys to tell me what to do? I can do this in excel with a formula but I have so much data that excel crashes so I really need 'R' but have very minimal knowledge about it...thanks guys....

推荐答案

运行相同的代码.为什么要编辑by=3?您要创建idx = 1, 3, 5 .... by=3,将创建​​1, 4, 7....您的数据,只要采用Time, data, Time, data, Time, data, ..., ...格式,就可以使用相同代码

Run the same code. Why are you editing by=3? You want to create idx = 1, 3, 5 .... by=3, will create 1, 4, 7.... Your data, as long as it is in the format Time, data, Time, data, Time, data, ..., ..., you can use the same code

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

这篇关于R编程修复错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆