我有一个角色矢量:
FINDINGS<-c("FD_BarrettDetail", "The segment looks flat.", "Prague score C0M3",
"It is x cm in length.", "This is an ultra-short segment.", "FD_BarrettDetail1_Benign",
"The segment looks flat.", "No nodularity is present.", "It is a long segment.",
"Some areas of vascular abnormalities are seen.", "The pit pattern is normal.")
我想提取FD_BarrettDetail
和FD_BarrettDetail1_Benign
之间的所有值(不包括分隔符),以便我得到:
Extract<-c("The segment looks flat.", "Prague score C0M3",
"It is x cm in length.", "This is an ultra-short segment.")
答案 0 :(得分:3)
使用==
和which
创建开始和结束的索引,以捕获此间隔内的所有内容。
> start <- which(FINDINGS=="FD_BarrettDetail")+1
> end <- which(FINDINGS=="FD_BarrettDetail1_Benign")-1
> FINDINGS[start:end]
[1] "The segment looks flat." "Prague score C0M3" "It is x cm in length."
[4] "This is an ultra-short segment."
>