Re: [R] Pattern Matching

2014-03-03 Thread arun
Hi, You could try: as.numeric(gsub(".*[(]([0-9]+)[)]","\\1",aa)) #[1] 472 445 431 431 415 405   1 #or library(gsubfn)  strapply(aa,"[(]([0-9]+)[)]",as.numeric,simplify=TRUE) #[1] 472 445 431 431 415 405   1 A.K. On Sunday, March 2, 2014 2:57 PM, "Doran, Harold" wrote: Suppose I have a chara

Re: [R] Pattern Matching

2014-03-02 Thread Ted Harding
On 02-Mar-2014 20:12:57 Benno Pütz wrote: > Try > > as.numeric(sub(".*\\(","", sub('\\)','',aa))) > > You may also want to look at regexec/regmatches for a more general approach > ... > > On 02 Mar 2014, at 20:55, Doran, Harold wrote: > >> "1 (472)" "2 (445)" "3 (431)" "3 (431)" "5 (415)" "6 (

Re: [R] Pattern Matching

2014-03-02 Thread Benno Pütz
Try as.numeric(sub(".*\\(","", sub('\\)','',aa))) You may also want to look at regexec/regmatches for a more general approach ... On 02 Mar 2014, at 20:55, Doran, Harold wrote: > "1 (472)" "2 (445)" "3 (431)" "3 (431)" "5 (415)" "6 (405)" "7 (1)” Benno Pütz Statistical Genetics MPI of Psychia

[R] Pattern Matching

2014-03-02 Thread Doran, Harold
Suppose I have a character vector as follows: > aa [1] "1 (472)" "2 (445)" "3 (431)" "3 (431)" "5 (415)" "6 (405)" "7 (1)” I want to extract the values within parentheses and place them into a column that is numeric. The values in aa vary in length and so using strsplit() won’t work because the

Re: [R] pattern matching

2013-01-07 Thread William Dunlap
p-boun...@r-project.org] On > Behalf > Of Data Analytics Corp. > Sent: Monday, January 07, 2013 1:22 PM > To: r-help@R-project.org > Subject: [R] pattern matching > > Hi, > > I have a simple question. Suppose I have a string "x$Expensive". I want > to fin

Re: [R] pattern matching

2013-01-07 Thread arun
HI, str1<-"x$Expensive" regexpr("\\$",str1)[1] #[1] 2  str2<-"x$Exp$Expression" unlist(gregexpr("\\$",str2)) #[1] 2 6 A.K. - Original Message - From: Data Analytics Corp. To: "r-help@R-project.org" Cc: Sent: Monday, Janua

Re: [R] pattern matching

2013-01-07 Thread Marc Schwartz
On Jan 7, 2013, at 3:22 PM, Data Analytics Corp. wrote: > Hi, > > I have a simple question. Suppose I have a string "x$Expensive". I want to > find the position of the $ in this string; i.e., I want a function that > returns 2. I tried grep, regexpr, etc with no luck, unless I'm just using

[R] pattern matching

2013-01-07 Thread Data Analytics Corp.
Hi, I have a simple question. Suppose I have a string "x$Expensive". I want to find the position of the $ in this string; i.e., I want a function that returns 2. I tried grep, regexpr, etc with no luck, unless I'm just using them incorrectly. Any suggestions? Thanks, Walt __

Re: [R] pattern matching

2012-10-10 Thread Rui Barradas
Hello, Try the following. pattern <- "between [[:digit:]]+ to [[:digit:]]+" re <- regexpr(pattern, string) regmatches(string, re) Hope this helps, Rui Barradas Em 10-10-2012 12:45, arunkumar escreveu: hi My string contain string = "The sales is good when my num1 between 1 to 5 . else

Re: [R] pattern matching

2012-10-10 Thread Gurubaramurugeshan, Arun
- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of arunkumar Sent: Wednesday, October 10, 2012 6:46 AM To: r-help@r-project.org Subject: [R] pattern matching hi My string contain string = "The sales is good when my num1 between 1 to 5 . else the sal

[R] pattern matching

2012-10-10 Thread arunkumar1111
hi My string contain string = "The sales is good when my num1 between 1 to 5 . else the sales is poor". i want to find the patten between 1 to 5 . between and to will be constant but the numbers would be changing. How to search for that pattern. Please help - Thanks in Advance

Re: [R] Pattern matching and replacement in matrix

2010-05-19 Thread Ivan Calandra
Hi, I think you can make it work by combining gsub() and sapply() (or lapply()), though I don't really know how (those *apply() functions are still kind of a mystery for me). Maybe someone else can help you Ivan Le 5/19/2010 12:35, Dani Valverde a écrit : Hello, Is there any function like g

Re: [R] Pattern matching and replacement in matrix

2010-05-19 Thread Gabor Grothendieck
Try this: DF <- data.frame(a = head(letters), A = head(LETTERS)) DF[] <- lapply(DF, gsub, pattern = "a", replacement = "X") m <- cbind(a = head(letters), A = head(LETTERS)) m[] <- gsub("a", "X", m) In the future please provide test data and desired output as per posting guide (see bottom of ever

Re: [R] Pattern matching and replacement in matrix

2010-05-19 Thread jim holtman
Exactly how do you want to do that? (PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.) Provide a before/after example of what you want. You could use the 'apply' functions. On Wed, May 19, 2010 at 6:35

[R] Pattern matching and replacement in matrix

2010-05-19 Thread Dani Valverde
Hello, Is there any function like gsub(), that can match and replace patterns in a matrix or a data frame? Cheers! Dani -- Daniel Valverde Saubí Grup de Biologia Molecular de Llevats Facultat de Veterinària de la Universitat Autònoma de Barcelona Edifici V, Campus UAB 08193 Cerdanyola del Val

Re: [R] Pattern Matching within Vector?

2009-09-21 Thread Charlie Sharpsteen
On Mon, Sep 21, 2009 at 8:07 AM, Anne-Marie Ternes wrote: > Dear mailing list, > > I'm stuck with a tricky problem here - at least it seems tricky to me, > being not really talented in pattern matching and regex matters. > > I'm analysing amino acid mutations by position and type of mutation. > E.

[R] Pattern Matching within Vector?

2009-09-21 Thread Anne-Marie Ternes
Dear mailing list, I'm stuck with a tricky problem here - at least it seems tricky to me, being not really talented in pattern matching and regex matters. I'm analysing amino acid mutations by position and type of mutation. E.g. (fictitious example) in position 92, I can find L92V, L92MV, L92I...

Re: [R] pattern matching

2008-10-27 Thread John Lande
On Sun, Oct 26, 2008 at 8:06 PM, Duncan Murdoch <[EMAIL PROTECTED]>wrote: > On 26/10/2008 11:54 AM, John Lande wrote: > >> dear all, >> >> I have a little problem I am doing a loop, witha grep function. sometimes >> it >> happens that have the following results >> >> tmp <- grep("x", y) >>> tmp

Re: [R] pattern matching

2008-10-26 Thread Duncan Murdoch
On 26/10/2008 11:54 AM, John Lande wrote: dear all, I have a little problem I am doing a loop, witha grep function. sometimes it happens that have the following results tmp <- grep("x", y) tmp integer(0) how can I recognise this outcome? is.na is not working of course, so what else? leng

Re: [R] pattern matching

2008-10-26 Thread Marc Schwartz
on 10/26/2008 10:54 AM John Lande wrote: > dear all, > > I have a little problem I am doing a loop, witha grep function. sometimes it > happens that have the following results > >> tmp <- grep("x", y) >> tmp > integer(0) > > > how can I recognise this outcome? is.na is not working of course, s

[R] pattern matching

2008-10-26 Thread John Lande
dear all, I have a little problem I am doing a loop, witha grep function. sometimes it happens that have the following results > tmp <- grep("x", y) > tmp integer(0) how can I recognise this outcome? is.na is not working of course, so what else? thank you [[alternative HTML version d

Re: [R] Scripting in R -- pattern matching, logic, system calls, the works!

2008-09-16 Thread Dan Davison
in a linear > >>regression. > >> > >>What I want to do is, write a script that looks in each of the coverage > >>directories and then reads in each of the files, takes the means, and > plots > >>them in form I specified above. The catch is, what if I only

Re: [R] Scripting in R -- pattern matching, logic, system calls, the works!

2008-09-16 Thread bioinformatics_guy
n(string) >>{ >> grep(string,dir(),value=T) >>} >> >>### I believe this is looking for all files of form below >>subdir = ll("Coverage_[1-9][0-9]$") >> >>### A for loop iterating through each of the sub directories. >>for (

Re: [R] Pattern Matching Replacement

2008-06-19 Thread Hans-Jörg Bibiko
On 19.06.2008, at 20:17, ppatel3026 wrote: I would like to replace "\r\n" with "" in a character string, where "\r\n" exists only between < and >, how could I do that? Initial: characterString = "\r\n" Result: characterString = "\r\nXML>" Tried with sub(below) but it only replaces the f

Re: [R] Pattern Matching Replacement

2008-06-19 Thread Gabor Grothendieck
On Thu, Jun 19, 2008 at 2:17 PM, ppatel3026 <[EMAIL PROTECTED]> wrote: > > I would like to replace "\r\n" with "" in a character string, where "\r\n" > exists only between < and >, how could I do that? > > Initial: > characterString = " id=\"F\r\n2\">\r\n" > > Result: > characterString = "\r\n" > >

[R] Pattern Matching Replacement

2008-06-19 Thread ppatel3026
I would like to replace "\r\n" with "" in a character string, where "\r\n" exists only between < and >, how could I do that? Initial: characterString = "\r\n" Result: characterString = "\r\n" Tried with sub(below) but it only replaces the first instance and I am not sure how to pattern match s

Re: [R] "pattern matching" accross multiple matrices

2007-11-08 Thread Gabor Grothendieck
Assume entries which are neither Case1 nor Case2 should be set to 0. Then: Case1 * (A == 1) * (D == 1) * (P == 1) + Case2 * (A == -1) * (D == -1) * (P == -1) # if A, D and P have their component values in the set [-1, 1] then this works too: Case1 * (pmin(A, D, P) == 1) + Case2 * (pmax(A, D, P)

Re: [R] "pattern matching" accross multiple matrices

2007-11-08 Thread jim holtman
You are putting your results back into "A" which might change things as you execute. This might be a faster way: result <- matrix(NA,dim(A)[1], dim(A)[2]) # now compute the cases result[(A ==1) & (D == 1) & (P ==1)] <- Case1 result[(A == -1) & (D == -1) & (P == -1)] <- Case2 ... On Nov 8, 2

[R] "pattern matching" accross multiple matrices

2007-11-08 Thread Martin Tomko
Hi all, I have a set of patterns which can occur in a series of (3) matrices. I want to identify those and create a fourth one with the identifiers of the cases. Something like: for (i in 1:l) { for (j in 1:w) { A[A[i,j]==1 & D[i,j]==1 & P[i,j]=

[R] "pattern matching" accross multiple matrices

2007-11-08 Thread Martin Tomko
Hi all, I have a set of patterns which can occur in a series of (3) matrices. I want to identify those and create a fourth one with the identifiers of the cases. Something like: for (i in 1:l) { for (j in 1:w) { A[A[i,j]==1 & D[i,j]==1 & P[i,j]=