2
여기
는 예를 들어 데이터 집합은 다음과 같습니다R에서 단어의 문자열을 머리 글자로 변환하고 다른 행의 데이터와 연결할 수 있습니까?
data <- data.frame (author = c('bob', 'john', 'james'),
year = c(2000, 1942, 1765),
title = c('test title one two three',
'another test title four five',
'third example title'))
그리고 나는하여 BibTex 참조, 예를 만드는 과정을 자동화하고 싶습니다 이 같은 기능 :
bibtexify <- function (author, year, title) {
acronym <- convert.to.acronym(title)
paste(author, year, acronym, sep='')
}
그래서 나는 다음과 같은 결과를 얻을 :
with(data, bibtexify(author, year, title))
[1] 'bob2000tto'
[2] 'john1942att'
[3] 'james1765tet'
는 R에서이 작업을 수행하는 것이 가능을?
감사합니다.
이 각 제목에 적어도 세 단어가 있다고 가정title <- c('test title one two three',
'another test title four five',
'third example title')
library(gsubfn)
sapply(strapply(title, "([a-zA-Z])[a-zA-Z]*"), function(x) paste(x[1:3], collapse=''))
, 그 경우 고정해야합니다 : 당신이 여기
R> abbreviate('test title one two three')
test title one two three
"ttott"
매우 좋습니다. 그 트릭을 보여 주셔서 고마워요! –