Displaying 20 results from an estimated 2000 matches similar to: "Pattern match"
2013 Jan 07
3
pattern matching
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
________________________
Walter R. Paczkowski, Ph.D.
Data Analytics Corp.
44 Hamilton Lane
Plainsboro,
2017 Aug 23
0
Comparing 2 dale columns
Patrick,
## Run the following script an notice the different values of the dataframe "data" in each instance.
# I understand you have done something like the following:
data <- data.frame(COL1 = c("6/1/14", "7/1/14"),
COL2 = c("5/1/15", "5/1/15"), stringsAsFactors = FALSE)
data$Date_Flag <- ifelse(data$COL2 >
2017 Jul 05
3
Please help(urgent) - How to simulate transactional data for reliability/survival analysis
A small example data set that illustrates your question will be of great value to those trying to help. This appears to be a transformation that you are wanting to do (timestamp to units of time) so a data representing what you have (dput() is handy for this) and one representing what you want to have with any guidance regarding how to use the other columns in you data set (e.g., the event(0/1)).
2013 Apr 03
1
(no subject)
Hello,
I want to perform a latent class analysis using poLCA package. My formula
is:
substances <- cbind(subs1, subs2, subs3, subs4, subs5, subs6) ~
gender+age+education+income+occupation+urban+dbehavior+incarceration+treatment+depression+alcriteria
I want to include sample weights in the model, I have read that poLCA does
not take into account weights, but when I introduce them, it seems
2017 Jul 05
0
Please help(urgent) - How to simulate transactional data for reliability/survival analysis
Mark,
Below is the sampled simulated granular data format for pumps for
trial period of 3 months that I need to transform for survival
analysis:
3 months = (60*24*90) minutes i.e 129600 minutes
pump_id timings events vibration temprature flow
pump1 01-07-2017 00:00 0 3.443 69.6 139.806
pump1 01-07-2017 00:10 1 0.501 45.27 140.028
2024 Mar 01
1
gsub issue with consecutive pattern finds
Hi Iago,
This is not a bug. It is expected. Patterns may not overlap. However, there
is a way to get the result you want using perl:
```R
gsub("([aeiouAEIOU])(?=[aeiouAEIOU])", "\\1_", "aerioue", perl = TRUE)
```
The specific change I made is called a positive lookahead, you can read
more about it here:
https://www.regular-expressions.info/lookaround.html
2024 Mar 01
1
gsub issue with consecutive pattern finds
Hi Iris,
Thank you. Further, very nice solution.
Best,
Iago
On 01/03/2024 12:49, Iris Simmons wrote:
> Hi Iago,
>
>
> This is not a bug. It is expected. Patterns may not overlap. However, there
> is a way to get the result you want using perl:
>
> ```R
> gsub("([aeiouAEIOU])(?=[aeiouAEIOU])", "\\1_", "aerioue", perl = TRUE)
> ```
>
2024 Mar 01
1
gsub issue with consecutive pattern finds
Hi all,
I tested next command:
gsub("([aeiouAEIOU])([aeiouAEIOU])", "\\1_\\2", "aerioue")
with the following output:
[1] "a_eri_ou_e"
So, there are two consecutive vowels where an underscore is not added.
May it be a bug? Is it expected (bug or not)? Is there any chance to get
what I want (an underscore between each pair of consecutive vowels)?
2024 Mar 01
1
gsub issue with consecutive pattern finds
Here's another *incorrect* way to do it -- incorrect because it will
not always work, unlike Iris's correct solution. But it does not
require PERL type matching. The idea: separate the two vowels in the
regex by a character that you know cannot appear (if there is such)
and match it optionally, e.g. with '*" repetition specifier. I used
"?" for the optional character
2008 Feb 03
4
Extract vowels and consonants using Ruby Regex
Hello,
I am trying to build a regex to extract vowels and consonants from a
string. So far, I am able to extract the basic a-e-i-o-u sequence
using the following extension to the String class:
class String
def vowels
scan(/[aeiou]/i)
end
def consonants
scan(/[^aeiou]/i)
end
end
examples:
>> "Mary had a little lamb".vowels
=> aaaiea
>> "Mary had a
2006 Feb 01
1
Word boundaries and gregexpr in R 2.2.1
Hi
I have a question concerning how to match word boundaries which I bet has a very simple answer, but I haven't found it with trial and error nor by searching the help archives for the terms in the subject line. The problem is this: I have a vector of two character strings.
text<-c("This is a first example sentence.", "And this is a second example sentence.")
If I
2007 Aug 02
4
Finding multiple characters in the same string
Hi
I have this problem where I need to find if there is any numbers in a
string, this is no problem if theres only one number per string. I would
then simply use the regexpr() funtion togheter with the substring function
to extract the number. But regexpr only picks one number per string either
from the beginning or the end, but not multiple. Can this be done? And how
for example
My string <-
2007 May 22
1
regexp bug in very recent r-devel
completion is semi-broken in today's r-devel, and the reason seems to
be some regular expression changes:
> sessionInfo()
R version 2.6.0 Under development (unstable) (2007-05-22 r41673)
i686-pc-linux-gnu
locale:
[...]
attached base packages:
[1] "stats" "graphics" "grDevices" "utils" "datasets" "methods"
[7]
2006 Nov 09
1
invert argument in grep
Hello,
What about an `invert` argument in grep, to return elements that are
*not* matching a regular expression :
R> grep("pink", colors(), invert = TRUE, value = TRUE)
would essentially return the same as :
R> colors() [ - grep("pink", colors()) ]
I'm attaching the files that I modified (against today's tarball) for
that purpose.
Cheers,
Romain
--
2005 Nov 03
3
Search within a file
Hi,
I am looking for a way to search a file for position of some expression,
from within R. My current code:
sha1Pos = gregexpr("<sha1>", readChar(filename,
file.info(filename)$size))[[1]]
Works fine for small files, but text files I will be working with might get
up to Gb range, so I was trying to accomplish the same without loading the
whole file into R.
I realize this is
2012 Mar 30
1
How to use access results of gregexpr in data frames
Hello,
I'm trying to figure out how to find the index of the second occurrence of "/" in a string (which happens to represent a date) within a data frame column.
I've used the following code successfully to find the first instance of "/".
dframe <- data.frame(date=c("5/14/2011", "4/7/2011"))
dframe$x1 <- regexpr("/", dframe[, 1])
2006 Feb 01
1
Word boundaries and gregexpr in R 2.2.1 (PR#8547)
Full_Name: Stefan Th. Gries
Version: 2.2.1
OS: Windows XP (Home and Professional)
Submission from: (NULL) (68.6.34.104)
The problem is this: I have a vector of two character strings.
> text<-c("This is a first example sentence.", "And this is a second example
sentence.")
If I now look for word boundaries with regexpr, this is what I get:
>
2008 Dec 12
4
gregexpr - match overlap mishandled (PR#13391)
Full_Name: Reid Thompson
Version: 2.8.0 RC (2008-10-12 r46696)
OS: darwin9.5.0
Submission from: (NULL) (129.98.107.177)
the gregexpr() function does NOT return a complete list of global matches as it
should. this occurs when a pattern matches two overlapping portions of a
string, only the first match is returned.
the following function call demonstrates this error (although this is not how I
2008 Dec 12
4
gregexpr - match overlap mishandled (PR#13391)
Full_Name: Reid Thompson
Version: 2.8.0 RC (2008-10-12 r46696)
OS: darwin9.5.0
Submission from: (NULL) (129.98.107.177)
the gregexpr() function does NOT return a complete list of global matches as it
should. this occurs when a pattern matches two overlapping portions of a
string, only the first match is returned.
the following function call demonstrates this error (although this is not how I
2017 Aug 23
2
Comparing 2 dale columns
Dear R fellows,
I created a new column Date_flag to compare the dates of COL1 and COL2 using the code
below. But it showed that 5/1/15 is greater than 6/1/2014 and 5/1/2015 greater than
7/1/2014 despite the year is greater. How do I fix that? I did try to format as %y/%m/%d
but it does not fix that.
data$Date_Flag <- ifelse(data$COL2 > data$COL1, 0,1)
COL1 COL2
6/1/14