[R] Differentiate alphanumeric vs numeric strings

Farrel Buchinsky fjbuch at gmail.com
Fri Apr 25 22:27:31 CEST 2008


This is fantastic.
As a future note to myself and to others who may stumble upon this:
further documentation for all one's heart could desire is in the base
help system at.

Regular Expressions as used in R - regexp

Pattern Matching and Replacement - grep

Split the Elements of a Character Vector  - strsplit

The following worked in my situation:
channel2007<-odbcConnectAccess("filename for 2007 data")
tables <-sqlTables(channel2007)[,3]
tables <-grep("[[:digit:]]",tables,value=TRUE)
all2007 <-sqlFetch(channel2007, tables[1])
for (f in tables[-1]) all2007<-rbind(all2007, sqlFetch(channel2007, f))

Thanks for your help



On Thu, Apr 24, 2008 at 11:34 PM, jim holtman <jholtman at gmail.com> wrote:
> The following will return the indices or the values of character
> strings that are all numeric:
>
> > x <- c("12345", "123AS23", "A123", "398457")
> > grep("^[[:digit:]]*$", x)   # index
> [1] 1 4
> > grep("^[[:digit:]]*$", x, value=TRUE)   # values
> [1] "12345"  "398457"
>
>
>
> >
>
>
>
> On Thu, Apr 24, 2008 at 10:39 PM, Farrel Buchinsky <fjbuch at gmail.com> wrote:
> > I have a bunch of tables in a Microsoft Access database. An updated database
> > is sent to me every week containing a new table. I know that is inefficient
> > and weird but welcome to my life. I want to read the tables whose names are
> > something such as "040207" but not the ones that have alphanumeric names
> > such as "everyone". Using RODBC I am easily able to create a character
> > vector of the names of the tables. Is there a function that can
> > differentiate values consisting only of digits (numerics) as opposed to ones
> > that contain letters (and perhaps digts as well)? I am sure there is. What
> > is it and where should I have found it?
> >
> > --
> > Farrel Buchinsky
> > GrandCentral Tel: (412) 567-7870
> >
> >        [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > 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.
> >
>
>
>
> --
> Jim Holtman
> Cincinnati, OH
> +1 513 646 9390
>
> What is the problem you are trying to solve?
>



-- 
Farrel Buchinsky
GrandCentral Tel: (412) 567-7870



More information about the R-help mailing list