Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert string of words to a custom acronym/abbreviation in R and concatenate it with data from other rows?

Here is an example data set:

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'))

And I would like to automate the process of making bibtex references, e.g. with a function like this:

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

so that I get the following result:

with(data, bibtexify(author, year, title))
[1] 'bob2000tto'
[2] 'john1942att'
[3] 'james1765tet'

Is it possible to do this in R?

like image 490
David LeBauer Avatar asked Dec 07 '22 00:12

David LeBauer


1 Answers

you want abbreviate

R> abbreviate('test title one two three')
test title one two three 
             "ttott" 
like image 146
Andrew Redd Avatar answered Jan 04 '23 22:01

Andrew Redd