如何从索引列表中选择嵌套列表中的字符串

时间:2019-03-17 19:11:14

标签: r

我有一个字符串列表(在数据框内)。我还有一个列表(与数据框中的列表大小相同),其编号与索引相对应。 我想提取第一个列表中与第二个列表中的整数相对应的那些元素。

这是我综合生成的数据

columnSentence<-list(c(",", ",Biopsies taken from top of stricture-metal marking clips in situ.", 
",Diaphragmatic pinch:40cm .,She has a small hiatus hernia .", 
"Dr. Martin, Marche Date of procedure: 2009-11-11 Endoscopist:", 
"Dr. Sullivan, Shelby Second endoscopist: Dr. al-Basha, Mahfoodha Medications:", 
"Extent of Exam: GOJ Indications: Follow-up ULCER HEALING Procedure Performed: Gastroscopy (OGD) Findings:", 
"Fentanyl 12.5mcg Midazolam 6mg Instrument: FG5", "HALO 90 done with good effect Endoscopic Diagnosis:", 
"He is on Barrett's Screeling List in October 2017 at St Thomas'.", 
"Hospital: Random NHS Foundation Trust Hospital Number: J6044658", 
"No evidence of Barrett's oesophagus, short 2 cn hiatus hernia.", 
",Oesophageal biopsies taken from three levels as requested.", 
",OGD today to assess for ulceration/ongoing bleeding.", "Patient Name: Jargon, Victoria General Practitioner:", 
"Post chemo-radiotherapy stricture", ",The varices flattened well with air insufflation.", 
"Tiny erosions at the antrum.", "We will re-book for 2 weeks, rebanding."
), c("Date of procedure: 2008-06-15 Endoscopist:", "Dr. al-Safi, Lutfiyya", 
"Dr. Kekich, Annabelle Second endoscopist: Dr. Needham, April Medications:", 
"Duodenitis with a small erosion .", "Endoscopic Diagnosis:", 
"Esophageal candidiasis", "Extent of Exam: Pylorus Indications: Weight Loss Procedure Performed: Gastroscopy (OGD) Findings: Duodenum:", 
"Fentanyl 125mcg Midazolam 7mg Instrument: FG6", "Hospital: Random NHS Foundation Trust Hospital Number: Y6417773 Patient Name: Powell, Destiny General Practitioner:", 
",STOMACH: diffuse gastritis with angiodysplasia and punctate bleeding site on greater curve mid body - no obvious ulcer- antrum scar ?,No immediate complications.", 
",Z-line at: 38cm - Bravo placed at 32cm- good positionat check endoscopy."
), c("Body Polyp- Pedunculated .,Several erosions/small ulcers in inflammed antrum.", 
"Date of procedure: 2007-10-27 Endoscopist:", "Dr. Rogers, Monica", 
"Dr. Sullivan, Shelby Second endoscopist: Dr. al-Basha, Mahfoodha Medications:", 
",DUODENUM: Normal to D3.", "Endoscopic Diagnosis:", "Extent of Exam: GOJ Indications: Follow-up ULCER HEALING Procedure Performed: Gastroscopy (OGD) Findings:", 
"Fentanyl 125mcg Midazolam 6mg Instrument: FG2", "Hospital: Random NHS Foundation Trust Hospital Number: B6072011", 
",Lax cardia with small hiatus hernia but no erosive oesophagitis.", 
"Patient Name: Martinez-Santos, Ana General Practitioner:", "Post chemo-radiotherapy stricture ,Extensive neoplastic looking esophageal lesion Esophageal candidiasis", 
"Stomach-"))

索引列表:

myIndexes<-list(c(2L, 4L), 1L, 2L)

如何提取与myIndexes列表相对应的句子?

1 个答案:

答案 0 :(得分:3)

我们可以使用Map根据'myIndexes'中相应的[索引提取(listlist('columnSentence')的句子

Map(`[`, columnSentence, myIndexes)

或使用map2中的purrr

library(purrr)
map2(columnSentence, myIndexes, `[`)