The problem is I have a list of character vectors.
example:
mylist <- list( c("once","upon","a","time"),
c("once", "in", "olden", "times"),
c("Let","all","good","men"),
c("Let","This"),
c("once", "is","never","enough"),
c("in","the"),
c("Come","dance","all","around"))
and I want to prepend c("one", "two") to those vectors starting "once" to end up with the list
mylist <- list( c("one", "two", "once","upon","a","time"),
c("one", "two", "once", "in", "olden", "times"),
c("Let","all","good","men"),
c("Let","This"),
c("one", "two", "once", "is","never","enough"),
c("in","the"),
c("Come","dance","all","around"))
so far
I can select the relevant vectors
mylist[grep("once",mylist)]
and I can prepend "one" and "two" to create a results list
resultlist <- lapply(mylist[grep("once",mylist)],FUN = function(listrow) prepend(listrow,c("One","Two")))
But putting the results in the correct place in mylist?
Nope, that escapes me!
Hints, tips and solutions most welcome :-)