【发布时间】:2015-11-27 02:41:14
【问题描述】:
我有一个这样的字符串向量:
x <- c("ermanaric cayce nonwashable climactical outseeing dorr nubble",
"aver unsegregating preprofess lumme noontime triskele",
"riverbank walachian penza",
"schlieren calthrop",
"hutlike paraphyllium unservile chaplainship bordelaise",
"phlogotic strategics jowlier orthopaedic nonprofiteering",
"vizir rudenture shopkeeper",
"interestuarine sardis",
"anthas figuring",
"unphased engle german emporium organometallic didy uneclipsing",
"bronzy conant reballot",
"extrados facinorous acrolithic",
"paralyzation uningratiating enzymatically enuresis",
"unscholastic extemporarily",
"discipleship fossilize summae",
"concretize intercharge palpate gombroon initiatrices",
"intimation progressiveness",
"unpictorialise",
"romanticization",
"wynnewood",
"unmate libratory polysynthetic")
有些元素需要粘贴在一起形成更长的字符串。我有一个向量列表,其中包含必须粘贴在一起的元素的索引:
indx <- list(c(3, 4), c(7, 8, 9), c(11, 12), c(14, 15), c(17, 18, 19, 20))
也就是说,第3个和第4个元素必须粘贴在一起形成字符串"riverbank walachian penza schlieren calthrop",第7、8和9个字符串要粘贴在一起形成字符串"vizir rudenture shopkeeper interestuarine sardis anthas figuring"等等(编辑),保持其余字符串的顺序相同。生成的字符串向量如下所示:
y <- c("ermanaric cayce nonwashable climactical outseeing dorr nubble",
"aver unsegregating preprofess lumme noontime triskele",
"riverbank walachian penza schlieren calthrop",
"hutlike paraphyllium unservile chaplainship bordelaise",
"phlogotic strategics jowlier orthopaedic nonprofiteering",
"vizir rudenture shopkeeper interestuarine sardis anthas figuring",
"unphased engle german emporium organometallic didy uneclipsing",
"bronzy conant reballot extrados facinorous acrolithic",
"paralyzation uningratiating enzymatically enuresis",
"unscholastic extemporarily discipleship fossilize summae",
"concretize intercharge palpate gombroon initiatrices",
"intimation progressiveness unpictorialise romanticization wynnewood",
"unmate libratory polysynthetic")
我尝试了以下方法但没有成功:
myfun <- function(obj, indx) {
paste(obj)[length(indx)]
}
mapply(myfun, x, m)
有人可以帮忙吗?
【问题讨论】: