Re: [R] regular expression question

From: Joshua Wiley <jwiley.psych_at_gmail.com>
Date: Mon, 11 Apr 2011 23:12:39 -0700

Hi Erin,

Please read ?grep. It is clearly not the function you want (neither is strsplit() either really). This does what you want and you can modify for upper/lower case if you need it. Also note that regular expressions exist separate from R, so while ":" may have seemed natural to select a range in R, it has a very different function in regexp.

gsub("[^A-Za-z]", "", names(funky))

Best regards,

Josh

On Mon, Apr 11, 2011 at 10:49 PM, Erin Hodgess <erinm.hodgess_at_gmail.com> wrote:
> Dear R People:
>
> I have a data frame with the following column names:
>
>> names(funky)
>  [1] "UHD.1"   "UHD.2"   "UHD.3"   "UHD.4"   "L..W..1" "L..W..2" "L..W..3"
>  [8] "L..W..4" "B..W..1" "B..W..2" "B..W..3" "B..W..4" "W..B..1" "W..B..2"
> [15] "W..B..3" "W..B..4" "B..G..1" "B..G..2" "B..G..3" "B..G..4"
>
>
> I would like to extract the letters from them; no periods, no numbers.
>
> I tried the following:
>
>> grep("[A:Z]",names(funky))
> integer(0)
>
> But this doesn't do it.
>
> I've also been experimenting with strsplit, but no luck yet.
>
> Any help would be much appreciated.
>
> Thanks,
> Sincerely,
> Erin
>
>
> --
> Erin Hodgess
> Associate Professor
> Department of Computer and Mathematical Sciences
> University of Houston - Downtown
> mailto: erinm.hodgess_at_gmail.com
>
> ______________________________________________
> 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.
>

-- 
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.com/

______________________________________________
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.
Received on Tue 12 Apr 2011 - 06:22:30 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 12 Apr 2011 - 07:10:29 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive