using lapply is so great. That help me a lot.
thanks.
Stephen Tucker wrote:
>
> I think you are looking for paste().
>
> And you can replace your for loop with lapply(), which will apply regexpr
> to
> every element of 'mylist' (as the first argument, which is 'pattern').
> 'text'
> can be a v
I think you are looking for paste().
And you can replace your for loop with lapply(), which will apply regexpr to
every element of 'mylist' (as the first argument, which is 'pattern'). 'text'
can be a vector also:
mylist <- c("MN","NY","FL")
lapply(paste(mylist,"$",sep=""),regexpr,text="Those fro
mylist=c("MN","NY","FL")
g=regexpr(paste(mylist[1], "$", sep=""), "Those from MN:")
if (g>0)
{
"On list"
}
or in a loop
for (i in mylist){
if (regexpr(paste(mylist[i], "$", sep="")) > 0){
.code for those from
}
}
On 6/29/07, runner <[EMAIL PROTECTED]> wrote:
>
>
> Hi,
>
Hi,
I 'd like to match each member of a list to a target string, e.g.
--
mylist=c("MN","NY","FL")
g=regexpr(mylist[1], "Those from MN:")
if (g>0)
{
"On list"
}
--
My question is:
How to add an end-of-string symbol '$' to the to-match strin
And here is an alternative to the regular expressions (although again
I don't think you really need any of this):
> capture.output(dput(strsplit("col1 col2 col3", " ")[[1]]))
[1] "c(\"col1\", \"col2\", \"col3\")"
On 1/30/07, Gabor Grothendieck <[EMAIL PROTECTED]> wrote:
> Both spaces and tabs are
On Tue, 2007-01-30 at 17:23 -0500, Kimpel, Mark William wrote:
> The main problem I am trying to solve it this:
>
> I am importing a tab delimited file whose first line contains only one
> column, which is a descriptor of the form "col_1 col_2 col_3", i.e. the
> colnames are not tab delineated but
Both spaces and tabs are whitespace so this
should be good enough (unless you can
have empty fields):
read.table("myfile.dat", header = TRUE)
See the sep= argument in ?read.table .
Although I don't think you really need this, here are
some regular expressions for processing a header
into the for
The main problem I am trying to solve it this:
I am importing a tab delimited file whose first line contains only one
column, which is a descriptor of the form "col_1 col_2 col_3", i.e. the
colnames are not tab delineated but are separated by whitespace. I would
like to parse this first line and m
On Tue, 2 Aug 2005, Marco Blanchette wrote:
> I am still forging my first arms with R and I am fighting with regexpr() as
> well as portability between unix and windoz. I need to extract barcodes from
> filenames (which are located between a double and single underscore) as well
> as the directory
Try this. The regular expression says to match
- anything
- followed by a double underscore
- followed by one or more digits
- followed by an underscore
- followed by anything.
The digits have been parenthesized so that they can be referred to in
the backreference "\\1".Also use the R fu
Dear all--
I am still forging my first arms with R and I am fighting with regexpr() as
well as portability between unix and windoz. I need to extract barcodes from
filenames (which are located between a double and single underscore) as well
as the directory where the filename is residing. Here is
n 2.54 (1.174.2.17-2003-05-11-exp)
>Content-Disposition: inline
>Content-Transfer-Encoding: 7bit
>Subject: [R] Regexpr with "."
>X-BeenThere: [EMAIL PROTECTED]
>X-Mailman-Version: 2.1.2
>List-Id: Main R Mailing List: Primary help
>List-Help: <mailto:[EMAIL PROTECTED]
Thompson, Trevor wrote:
It looks like R is treating every character in the string as if it were
decimal. I didn't see anything in the help file about "." being some kind
of special character. Any idea why R is treating a decimal this way in
these functions? Any suggestions how to get around th
Thompson, Trevor wrote:
I'm trying to use the regexpr function to locate the decimal in a character
string. Regardless of the position of the decimal, the function returns 1.
For example,
regexpr(".", "Female.Alabama")
[1] 1
attr(,"match.length")
[1] 1
In trying to figure out what was going on h
Try regexpr("\\.", "Female.Alabama")
-Original Message-
From: Thompson, Trevor [mailto:[EMAIL PROTECTED]
Sent: 13 August 2003 15:47
To: [EMAIL PROTECTED]
Subject: [R] Regexpr with "."
I'm trying to use the regexpr function to locate the decimal in a
c
I'm trying to use the regexpr function to locate the decimal in a character
string. Regardless of the position of the decimal, the function returns 1.
For example,
> regexpr(".", "Female.Alabama")
[1] 1
attr(,"match.length")
[1] 1
In trying to figure out what was going on here, I tried the below
On 13-Aug-03 Barry Rowlingson wrote:
> Thompson, Trevor wrote:
>> I didn't see anything in the help file about "." being some kind
>> of special character. Any idea why R is treating a decimal this
>> way in these functions? Any suggestions how to get around this?
>
> '.' is the regexpr charact
Thompson, Trevor wrote:
I'm trying to use the regexpr function to locate the decimal in a character
string. Regardless of the position of the decimal, the function returns 1.
For example,
regexpr(".", "Female.Alabama")
You probably want backslashes to indicate that "." should not
be treated as
> I'm trying to use the regexpr function to locate the decimal in a character
> string. Regardless of the position of the decimal, the function returns 1.
You need to escape it.
> gsub("\\.",",","Female.Alabama")
[1] "Female,Alabama"
__
[EMAIL PROTECT
Trevor,
The "." is a regex meta-character that matches any character. In order to look
specifically for a ".", the you must escape it with a "\", and that "\" must
also be escaped, thus,
> regexpr("\\.", "Female.Alabama")
[1] 7
attr(,"match.length")
[1] 1
>
HTH
steve
"Thompson, Trevor" wrote:
msg.pgp
Description: PGP message
21 matches
Mail list logo