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
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() wont
work because the
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
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
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
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
__
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
-
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
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
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
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
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.
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...
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
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
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
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 (
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"
>
>
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
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
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]=
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]=
30 matches
Mail list logo