[datatable-help] How to produce variations of a text?

affableambler nfields at gmail.com
Wed Nov 2 21:16:14 CET 2016


Easy, just use sapply.

desire<-"I want cats"
actions<-c("see","grab","obtain")

f<-function(x){
  gsub("want", x, desire)
}
sapply(actions,FUN=f)


            see            grab          obtain 
   "I see cats"   "I grab cats" "I obtain cats" 

Alternatively, you could use a for loop, however this is much less
efficient.


vector<-c()
for(action in actions){
  vector<-c(vector,gsub("want",action,desire))
}

print(vector)

[1] "I see cats"    "I grab cats"   "I obtain cats"



--
View this message in context: http://r.789695.n4.nabble.com/How-to-produce-variations-of-a-text-tp4726153p4726157.html
Sent from the datatable-help mailing list archive at Nabble.com.


More information about the datatable-help mailing list