0
我試圖從選項列表中創建虛擬數據:生成內插串N次,所以我得到n個不同的答案
library('stringr')
#Generate a load of strings
line <- list(x1 = 10, x2 = 30,x3="There is no intestinal metaplasia, dysplasia or malignancy",x4="No Helicobacter are seen",x5="There is some ulceration",x6="There is no intercellular oedema in the surface epithelium",x7="PASstaining shows occasional spores, consistent with candida",x8="No herpetic viral inclusions are seen",x9="There is no dysplasia and no invasive carcinoma",x10="There is mild regenerative epithelial change, but neither dysplasia nor malignancy is seen",x11="The appearances are consistent with the endoscopic diagnosis of Barrett's oesophagus with active chronic inflammation",x12="The biopsies of oesophageal squamous mucosa show surface erosion and active chronic inflammation",x13="Numerous Candida spores and hyphae are present admixed with ulcer slough",x14="There is reactive basal cell hyperplasia and mild inflammatory epithelial atypia",x15="There is no significant increase in intraepithelialeosinophils",x16="No granulomas or viral inclusions are seen",x17="The appearances are those of Candida oesophagitis",x18="Neither dysplasia nor malignancy is seen",x19="The appearances are consistent with, but not specific for Barrett's (columnar lined) oesophagus")
listofResults<-unlist(sample(line,2,replace=T))
list.of.samples <- replicate(1000, paste(sample(1:10,1), "specimens collected the largest measuring", sample(1:5,1) ,"x", sample(1:5,1) ,"x", sample(1:5,1), "mm and the smallest", sample(1:5,1) ,"x", sample(1:5,1) ,"x", sample(1:5,1), "mm"), simplify=FALSE)
我想然後創建數據的10個樣品。如果我運行:
#Merge the strings together randomly
histop<-paste (sample(list.of.samples,1,replace=T),str_c(sample(line,sample(3:10,1),replace=T),collapse='.'))
然後我得到隨機構造的字符串就好了,正如預期的那樣,每次運行它時都會發生變化。然而運行
rep(histop,10)
只是結果相同的結果10次。所以我試圖把它作爲一個功能
histop<-function(){
paste (sample(list.of.samples,1,replace=T),str_c(sample(line,sample(3:10,1),replace=T),collapse='.'))
}
rep(histop(),10)
但我得到了同樣的結果。我怎樣才能得到10個不同的字符串?