R:pi [[j]]中的错误:下标超出范围-数据框列表上的rbind [英] R: Error in pi[[j]] : subscript out of bounds -- rbind on a list of dataframes

查看:82
本文介绍了R:pi [[j]]中的错误:下标超出范围-数据框列表上的rbind的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试绑定大数据帧列表(outputDfList),该列表是通过将复杂的函数应用于大表而生成的.您可以通过以下方式重新创建outputDfList:

I am trying to rbind a large list of data frames (outputDfList), which is generated by lapply a complicated function to a large table. You can recreate outputDfList by:

df1=data.frame("randomseq_chr15q22.1_translocationOrInsertion", "chr15", "63126742")
names(df1)=NULL
df2=df1=data.frame("chr18q12.1_chr18q21.33_large_insertion", "chr18 ", "63126741")
names(df2)=NULL
outputDfList=list(df1,df2)

我的代码是

do.call(rbind, outputDfList)

我收到的错误消息:

Error in pi[[j]] : subscript out of bounds

我仔细检查了每个数据帧的列号,它们都相同.我也尝试使用"options(error = recover)"进行调试,但是我对它的熟悉程度不足以解决确切的问题.任何帮助表示赞赏.谢谢.

I double checked the column numbers of each dataframes and they are all the same. I also tried to use "options(error=recover)" for debug, but I'm not familiar with it enough to pitch down the exact issue. Any help is appreciated. Thank you.

推荐答案

更新后,看来您的问题是列名无效:数据框列名必须为非空.

After the update it seems that your problem is that you have invalid column names: Data frame column names must be non-null.

更正此错误之后,代码将起作用:

After correcting this, the code then works:

for (i in seq_along(outputDfList)) {
    colnames(outputDfList[[i]]) = paste0('V', seq_len(ncol(outputDfList[[i]])))
}

do.call(rbind, outputDfList)
#                                       V1     V2       V3
# 1 chr18q12.1_chr18q21.33_large_insertion chr18  63126741
# 2 chr18q12.1_chr18q21.33_large_insertion chr18  63126741

然而,我很困惑这种情况最初是如何发生的.此外,与您的代码一起收到的错误消息 still 与您的代码不同:

However, I’m puzzled how this situation occurred in the first place. Furthermore, the error message I’m getting with your code is still distinct from yours:

match.names(clabs,names(xi))中的错误:
名称与以前的名称不符

Error in match.names(clabs, names(xi)) :
names do not match previous names

这篇关于R:pi [[j]]中的错误:下标超出范围-数据框列表上的rbind的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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