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 othercharacters... [[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 Ryszard Czerminski AstraZeneca Pharmaceuticals LP 35 Gatehouse Drive Waltham, MA 02451 USA 781-839-4304 ryszard.czerminski@astrazeneca.com -------------------------------------------------------------------------- Confidentiality Notice: This message is private and may ...{{dropped:11}}
Hi Ryszard, Try strsplit("a.b", "[.]")[[1]] and see "Extended Regular Expressions" in ?regexp. HTH, Jorge,- On Thu, Jan 12, 2012 at 10:15 AM, Czerminski, Ryszard <> 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 > > > > Ryszard Czerminski > AstraZeneca Pharmaceuticals LP > 35 Gatehouse Drive > Waltham, MA 02451 > USA > 781-839-4304 > ryszard.czerminski@astrazeneca.com > > > -------------------------------------------------------------------------- > Confidentiality Notice: This message is private and may ...{{dropped:11}} > > ______________________________________________ > R-help@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. >[[alternative HTML version deleted]]
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
Because it uses regexp: use split='\\.' to split on "." char and read help(strsplit) :) Ryszard -------------------------------------------------------------------------- Confidentiality Notice: This message is private and may contain confidential and proprietary information. If you have received this message in error, please notify us and remove it from your system and note that you must not copy, distribute or take any action in reliance on it. Any unauthorized use or disclosure of the contents of this message is not permitted and may be unlawful. ? -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Czerminski, Ryszard Sent: Thursday, January 12, 2012 10:16 AM To: r-help Subject: [R] strsplit() does not split on "."? 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 othercharacters... [[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 Ryszard Czerminski AstraZeneca Pharmaceuticals LP 35 Gatehouse Drive Waltham, MA 02451 USA 781-839-4304 ryszard.czerminski at astrazeneca.com ------------------------------------------------------------------------ -- Confidentiality Notice: This message is private and may ...{{dropped:11}} ______________________________________________ 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.