【问题标题】:meaning of combn error: Error in FUN(X[[i]], ...) : n < m in R组合错误的含义: FUN 中的错误(X[[i]],...):n < m in R
【发布时间】:2016-04-12 10:21:23
【问题描述】:

尝试创建一对元素但得到以下错误:

Error in FUN(X[[i]], ...) : n < m

运行代码后出现错误:

rslt <- lapply(split(my$symbol, my$character), combn, 2, simplify = F)

这里my 是我的数据框,符号和字符是数据框的列。数据框包含 26,552 行。在这里,我发布了我的一小部分数据。

my:
symbol   character
BHMT    Abruptio Placentae
BHMT    Diabetes Mellitus, Type 2
BHMT    Lymphoma, Non-Hodgkin
BHMT    Neural Tube Defects
BID     Carcinoma, Hepatocellular
BID     Stomach Neoplasms
BIN1    Alzheimer Disease
BIN1    Myopathies, Structural, Congenital
BIN1    Myopathy, Centronuclear, Autosomal Recessive
BIRC5   Lung Neoplasms
BIRC5   Ovarian Neoplasms
BIRC5   Stomach Neoplasms
BIRC6   Neoplasms
BIRC7   Carcinoma, Renal Cell
BLK     Arthritis, Rheumatoid 
BLK     Lupus Erythematosus, Systemic
BLK     Maturity-onset diabetes of the young, type 11

任何帮助表示赞赏。谢谢。

【问题讨论】:

    标签: r combn


    【解决方案1】:

    这是元素数量少于“m”的情况之一。一种选择是为小于“m”的list 中的length 创建一个例外

    lapply(split(my$symbol, my$character), function(x)
              if(length(x)>1) {
                combn(x, 2, simplify=FALSE)
               }
               else x)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-22
      • 2018-06-28
      • 2017-12-12
      • 1970-01-01
      • 2021-02-06
      相关资源
      最近更新 更多