是否可以将字符串转换为R中的首字母缩写词,并将其与其他行的数据连接起来?

Dav*_*uer 3 text 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'))
Run Code Online (Sandbox Code Playgroud)

我想自动化制作bibtex引用的过程,例如使用这样的函数:

bibtexify <- function (author, year, title) {
      acronym <- convert.to.acronym(title)
      paste(author, year, acronym, sep='')
      }
Run Code Online (Sandbox Code Playgroud)

这样我得到以下结果:

with(data, bibtexify(author, year, title))
[1] 'bob2000tto'
[2] 'john1942att'
[3] 'james1765tet'
Run Code Online (Sandbox Code Playgroud)

可以在R中这样做吗?

谢谢!

And*_*edd 7

你要 abbreviate

R> abbreviate('test title one two three')
test title one two three 
             "ttott" 
Run Code Online (Sandbox Code Playgroud)