[R] strsplit() does not split on "."?
Sarah Goslee
sarah.goslee at gmail.com
Thu Jan 12 16:23:31 CET 2012
Reread the help for strsplit:
## Note that 'split' is a regexp!
## If you really want to split on '.', use
unlist(strsplit("a.b.c", "\\."))
## [1] "a" "b" "c"
## or
unlist(strsplit("a.b.c", ".", fixed = TRUE))
For your example:
> strsplit("a.b", "\\.")
[[1]]
[1] "a" "b"
In other words, nothing is wrong, and strsplit() behaves as documented.
Sarah
On Thu, Jan 12, 2012 at 10:15 AM, Czerminski, Ryszard
<Ryszard.Czerminski at astrazeneca.com> wrote:
> Any ideas what is wrong?
>
>> strsplit("a.b", ".") # generates empty strings with split="."
> [[1]]
> [1] "" "" ""
>
>> strsplit("a b", " ") # seems to work fine with split=" ", and other
> characters...
> [[1]]
> [1] "a" "b"
>>
>
>> R.Version()
> $platform
> [1] "x86_64-unknown-linux-gnu"
> $arch
> [1] "x86_64"
> $os
> [1] "linux-gnu"
> $system
> [1] "x86_64, linux-gnu"
> $status
> [1] ""
> $major
> [1] "2"
> $minor
> [1] "14.1"
> $year
> [1] "2011"
> $month
> [1] "12"
> $day
> [1] "22"
> $`svn rev`
> [1] "57956"
> $language
> [1] "R"
> $version.string
> [1] "R version 2.14.1 (2011-12-22)"
>
> Best regards,
> Ryszard
>
>
--
Sarah Goslee
http://www.functionaldiversity.org
More information about the R-help
mailing list