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
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 (
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
"$" has a special meaning (end-of-string) in regular expressions, so you can
either escape it with "\\" or not use regular expressions in regexpr():
> regexpr("\\$", "x$Expensive")
[1] 2
attr(,"match.length")
[1] 1
attr(,"useBytes")
[1] TRUE
> regexpr("$", "x$Expensive", fixed=TRUE)
[1] 2
attr(,"
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, January 7, 2013 4:22 PM
Subject: [R] pattern matching
Hi,
I have
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
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
This looks like a conceptual question rather than a R question. PLEASE do read
the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Arun Prasad Gurubaramurugeshan,
Senior Research Analyst
-Original Message-
Fro
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
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
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
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.
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
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
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
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
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"
>
>
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)
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
19 matches
Mail list logo