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

怎甘沉沦 提交于 2019-12-12 02:53:56

问题


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.


回答1:


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)


来源:https://stackoverflow.com/questions/36570399/meaning-of-combn-error-error-in-funxi-n-m-in-r

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!