我有一个执行文本处理任务的函数(ColumnCleanUp
)。该函数从另一个函数Extractor
调用。 ColumnCleanUp
在现实生活中具有各种功能,这些功能已归入功能组合。
我想按如下方式将每列传递给它:
Extractor <- function(dataframeIn, Column, delim) {
dataframeIn <- apply(dataframeIn, 2, function(x) ColumnCleanUp(dataframeIn,x))
return(dataframeIn)
}
ColumnCleanUp <- function(dataframe, Column) {
dataframe[, Column] <- gsub(",", "", dataframe[, Column], fixed = TRUE)
return(dataframe[, Column])
}
目前我正在将整个列传递给ColumnCleanUp
函数,而我只想传递名称。我怎样才能做到这一点?这个例子非常简单。
输入
structure(list(Histology = c(" Two biopsies consist of small bowel mucosa and are within normal histological limits\n\n",
" modified giemsa stain\n,These are biopsies of gastric mucosa ,There is no evidence of coeliac disease\n,The nuclei are hyperchromatic,\n,There is no granulomatous inflammation\n,The appearances are in keeping with a reactive/chemical gastritis,features including basal layer hyperplasia and reactive nucelar changes with underlying\n,These are two biopsies of squamous epithelium within normal limits,fibromuscularisation of the lamina propria and mild chronic inflammation\n,These biopsies of columnar mucosa show focal acute inflammation, moderate chronic inflammation\n\n"
), Diagnosis = c(" Distal transverse colon polyp excision:- tubular adenoma, low grade dysplasia\n,Ileo-caecal valve, biopsies:\n,Stomach antrum biopsies:- normal mucosa\n,- Up to 34 eosinophils per high power field,Stomach, biopsy - Mild chronic inflammation\n",
" Rectum, polyp biopsy: - Tubular adenoma with mild dysplasia,- Raised intra-epithelial lymphocytes ,Duodenum, biopsies - within normal histological limits\n,B GI biopsy - DISTAL OESOPHAGUS X2, MID OESO X3, PROX OESO X2\n,Oesophagus, biopsies : - Minimal chronic inflammation,Sigmoid colon, polypectomy: - Tubular adenoma with moderate dysplasia,Oesophagus polyps biopsies:- 2 x papillomas\n,Duodenum biopsies:- normal\n"
)), .Names = c("Histology", "Diagnosis"), class = "data.frame", row.names = 1:2)
所需的输出
structure(c(" Two biopsies consist of small bowel mucosa and are within normal histological limits\n\n",
" modified giemsa stain\nThese are biopsies of gastric mucosa There is no evidence of coeliac disease\nThe nuclei are hyperchromatic\nThere is no granulomatous inflammation\nThe appearances are in keeping with a reactive/chemical gastritisfeatures including basal layer hyperplasia and reactive nucelar changes with underlying\nThese are two biopsies of squamous epithelium within normal limitsfibromuscularisation of the lamina propria and mild chronic inflammation\nThese biopsies of columnar mucosa show focal acute inflammation moderate chronic inflammation\n\n",
" Distal transverse colon polyp excision:- tubular adenoma low grade dysplasia\nIleo-caecal valve biopsies:\nStomach antrum biopsies:- normal mucosa\n- Up to 34 eosinophils per high power fieldStomach biopsy - Mild chronic inflammation\n",
" Rectum polyp biopsy: - Tubular adenoma with mild dysplasia- Raised intra-epithelial lymphocytes Duodenum biopsies - within normal histological limits\nB GI biopsy - DISTAL OESOPHAGUS X2 MID OESO X3 PROX OESO X2\nOesophagus biopsies : - Minimal chronic inflammationSigmoid colon polypectomy: - Tubular adenoma with moderate dysplasiaOesophagus polyps biopsies:- 2 x papillomas\nDuodenum biopsies:- normal\n"
), .Dim = c(2L, 2L), .Dimnames = list(c("1", "2"), c("Histology",
"Diagnosis")))