meaning of combn error: Error in FUN(X[[i]], …) :

2019-09-09 15:33发布

Trying to create a pair of element but get the following error:

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

The error appears after running the code:

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

Here my is my data frame and symbol and character is column of data frame. the data frame contain 26,552 rows. Here i posted the small part of my data.

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

Any help appreciated. Thank you.

标签: r combn
1条回答
Deceive 欺骗
2楼-- · 2019-09-09 16:27

This is one of the cases where there are less number of elements than 'm'. One option would be to create an exception for length of list that are less than 'm'

lapply(split(my$symbol, my$character), function(x)
          if(length(x)>1) {
            combn(x, 2, simplify=FALSE)
           }
           else x)
查看更多
登录 后发表回答