[R] using an array of strings with strsplit, issue when including a space in split criteria

Juliet Hannah juliet.hannah at gmail.com
Tue Sep 8 03:17:43 CEST 2009


I get a different result:

txt <- c("sales to 23 August 2008 published 29 August","sales to 6
September 2008 published 11 September")
strsplit(txt, 'published ', fixed=TRUE)
[[1]]
[1] "sales to 23 August 2008 " "29 August"

[[2]]
[1] "sales to 6 September 2008 " "11 September"

> sessionInfo()
R version 2.9.0 (2009-04-17)
i386-pc-mingw32

locale:
LC_COLLATE=English_United States.1252;LC_CTYPE=English_United
States.1252;LC_MONETARY=English_United
States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base



On Mon, Sep 7, 2009 at 11:40 AM, Tony Breyal<tony.breyal at googlemail.com> wrote:
> Dear all,
>
> I'm having a problem understanding why a split does not occur with in
> the 2nd use of the function strsplit below:
>
> # text strings
>> txt <- c("sales to 23 August 2008 published 29 August",
> + "sales to 6 September 2008 published 11 September")
>
> # first use
>> strsplit(txt, 'published', fixed=TRUE)
> [[1]]
> [1] "sales to 23 August 2008 " " 29 August"
>
> [[2]]
> [1] "sales to 6 September 2008 " " 11 September"
>
> # second use, but with a space ' ' in the split
>> strsplit(txt, 'published ', fixed=TRUE)
> [[1]]
> [1] "sales to 23 August 2008 " "29 August"
>
> [[2]]
> [1] "sales to 6 September 2008 published 11 September"
>
> Thank you kindly for any help in advance.
> Tony
>
> O/S: Win Vista Ultimate
>> sessionInfo()
> R version 2.9.2 (2009-08-24)
> i386-pc-mingw32
>
> locale:
> LC_COLLATE=English_United Kingdom.1252;LC_CTYPE=English_United Kingdom.
> 1252;LC_MONETARY=English_United Kingdom.
> 1252;LC_NUMERIC=C;LC_TIME=English_United Kingdom.1252
>
> attached base packages:
> [1] stats     graphics  grDevices utils     datasets  methods
> base
>
> other attached packages:
> [1] RODBC_1.3-0
>
> ______________________________________________
> 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.
>




More information about the R-help mailing list