[R] separate the sentence after finding a particular word
Rui Barradas
ruipbarradas at sapo.pt
Thu Jun 14 16:12:19 CEST 2012
Hello,
I don't understand, do you want to output:
1st line: the original input line
2nd line: " I want output in following format " <-- this line
3rd line and following: the input line broken by the patterns
Then just
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", "\\.\\.+")
out <- Reduce(f, c(x, pat))
out <- c("1st line", "2nd line", out)
Rui Barradas
Em 14-06-2012 08:36, raishilpa escreveu:
> hello
> Can you help me further
> Is this possible to get output in the following way-
>
> [1 " ]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.. "
>
> [2] " I want output in following format "
> [3] " I love to watch movies of Hollywood "
> [4] " should not be romantic "
> [5] "I want to join you school'
> [6] " due to bad financial condition I cant "
>
>
>
>
> On Wed, Jun 13, 2012 at 11:57 PM, shilpa rai <raishilpa.bhu at gmail.com>wrote:
>
>> thanks a lot !!!
>
>
>
>
More information about the R-help
mailing list