Dear all I encountered strange problem with regexpr replacement I made this character object str <- "02.06.10 12:40 "> str(str)chr "02.06.10 12:40 " I read in an object which seems to be quite similar> str(as.character(becva$V1)[1])chr "02.06.10 12:40 " However I can not remove trailing spaces from it> sub(' +$', '', as.character(becva$V1[1]))[1] "02.06.10 12:40 "> sub(' +$', '', str)[1] "02.06.10 12:40">Do somebody have an idea what to do? $version.string [1] "R version 2.12.0 Under development (unstable) (2010-04-25 r51820)" on Windows Regards Petr
Could you provide us with dput(becva$V1[1])? Cheers Joris On Wed, Jun 2, 2010 at 2:07 PM, Petr PIKAL <petr.pikal@precheza.cz> wrote:> Dear all > > I encountered strange problem with regexpr replacement > > I made this character object > > str <- "02.06.10 12:40 " > > > str(str) > chr "02.06.10 12:40 " > > I read in an object which seems to be quite similar > > > str(as.character(becva$V1)[1]) > chr "02.06.10 12:40 " > > However I can not remove trailing spaces from it > > > sub(' +$', '', as.character(becva$V1[1])) > > [1] "02.06.10 12:40 " > > sub(' +$', '', str) > [1] "02.06.10 12:40" > > > > Do somebody have an idea what to do? > > $version.string > [1] "R version 2.12.0 Under development (unstable) (2010-04-25 r51820)" > > on Windows > > Regards > Petr > > ______________________________________________ > 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. >-- Joris Meys Statistical Consultant Ghent University Faculty of Bioscience Engineering Department of Applied mathematics, biometrics and process control Coupure Links 653 B-9000 Gent tel : +32 9 264 59 87 Joris.Meys@Ugent.be ------------------------------- Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php [[alternative HTML version deleted]]
On Wed, 2010-06-02 at 08:07 -0400, Petr PIKAL wrote:> Dear all > > I encountered strange problem with regexpr replacement > > I made this character object > > str <- "02.06.10 12:40 " > > > str(str) > chr "02.06.10 12:40 " > > I read in an object which seems to be quite similar > > > str(as.character(becva$V1)[1]) > chr "02.06.10 12:40 " > > However I can not remove trailing spaces from it > > > sub(' +$', '', as.character(becva$V1[1])) > > [1] "02.06.10 12:40 " > > sub(' +$', '', str) > [1] "02.06.10 12:40" > > > > Do somebody have an idea what to do?Could the white space in the string be a tab? If so, the space character will not match. Try something that matches multiple white space, like sub('\\w+$', '', as.character(becva$V1[1])) or sub('[[:blank:]]+$', '', as.character(becva$V1[1])) Matt Shotwell Graduate Student Division of Biostatistics and Epidemiology Medical University of South Carolina> > $version.string > [1] "R version 2.12.0 Under development (unstable) (2010-04-25 r51820)" > > on Windows > > Regards > Petr > > ______________________________________________ > 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.