hello, I want to know ..how we can separate the sentence after finding a particular word... for example I love to watch movies of Hollywood but should not be romantic...I want to join you school but due to bad financial condition I cant.. I want output in following format I love to watch movies of Hollywood should not be romantic I want to join you school due to bad financial condition I cant So whenever this but is coming in the sentence of a paragraph I want the sentence before but and after but in two different lines... Please help me.... Thanks in Advance Shilpa Rai Msc ( IIT Bombay) -- View this message in context: http://r.789695.n4.nabble.com/separate-the-sentence-after-finding-a-particular-word-tp4633240.html Sent from the R help mailing list archive at Nabble.com.
Rui Barradas
2012-Jun-13 14:51 UTC
[R] separate the sentence after finding a particular word
Hello, Try x <- scan(what="character", text="my name name name is micky") rle(x) paste(rle(x)$values, collapse=" ") Hope this helps, Rui Barradas Em 13-06-2012 13:06, raishilpa escreveu:> hello, > I want to know ..how we can separate the sentence after finding a particular > word... > for example > > I love to watch movies of Hollywood but should not be romantic...I want to > join you school but due to bad financial condition I cant.. > > I want output in following format > I love to watch movies of Hollywood > should not be romantic > I want to join you school > due to bad financial condition I cant > > So whenever this but is coming in the sentence of a paragraph I want the > sentence before but and after but in two different lines... > > Please help me.... > > Thanks in Advance > > Shilpa Rai > Msc ( IIT Bombay) > > -- > View this message in context: http://r.789695.n4.nabble.com/separate-the-sentence-after-finding-a-particular-word-tp4633240.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.
Rui Barradas
2012-Jun-13 15:10 UTC
[R] separate the sentence after finding a particular word
Hello, Sorry for my earlier reply, it was meant for another question you posted. In what follows, 'x' is your text. f <- function(x, pattern) unlist(strsplit(x, pattern)) x <- "I love to watch movies of Hollywood but should not be romantic...I want to join you school but due to bad financial condition I cant." x <- gsub("[[:space:]]+", " ", x) pat <- c("but", "\\.\\.+") # one period is ok, not 2 or more Reduce(f, c(x, pat)) # break it. Rui Barradas Em 13-06-2012 13:06, raishilpa escreveu:> hello, > I want to know ..how we can separate the sentence after finding a particular > word... > for example > > I love to watch movies of Hollywood but should not be romantic...I want to > join you school but due to bad financial condition I cant.. > > I want output in following format > I love to watch movies of Hollywood > should not be romantic > I want to join you school > due to bad financial condition I cant > > So whenever this but is coming in the sentence of a paragraph I want the > sentence before but and after but in two different lines... > > Please help me.... > > Thanks in Advance > > Shilpa Rai > Msc ( IIT Bombay) > > -- > View this message in context: http://r.789695.n4.nabble.com/separate-the-sentence-after-finding-a-particular-word-tp4633240.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.