You are the domain expert, but it would seem to me that "-NEGRO" is a part of
the ID because it uniquely specifies the product.
>From the perspective of expressing your business logic in code, dropping this
>part of the string should have a separate line in the code, and a comment.
>Dropping
On Oct 10, 2015, at 10:57 PM, Karim Mezhoud wrote:
> My code is not correct.
> The idea is to use apply instead of a loop. more efficiency.
There is no increased efficiency in using apply. Both `apply` and a `for` loop
will perform with equal efficiency. The only advantage is the mental
Thank you very much to both of you. This information is very enlightening
to me.
Cheers.
2015-10-10 1:11 GMT-05:00 Boris Steipe :
> David answered most of this. Just a two short notes inline.
>
>
>
>
> On Oct 10, 2015, at 12:38 AM, Omar André Gonzáles Díaz <
>
My code is not correct.
The idea is to use apply instead of a loop. more efficiency.
Karim
On Sun, Oct 11, 2015 at 6:42 AM, Omar André Gonzáles Díaz <
oma.gonza...@gmail.com> wrote:
> Thanks Karim. linio.tv is in the email. In the last part.
> El oct 11, 2015 12:39 AM, "Karim Mezhoud"
Hi,
omit unlist and test. otherwise you can use apply function.
draft:
df1 <- apply(linio.tv, 1, function(x) strsplit(x[,idproductio],
"[^A-Z0-9-]+"))
fct <- function(linio.tv){
if(any(grep("[A-Z][0-9]", linio.tv[,idx_productio]))) {
linio.tv[,idx(id)] <-
Thanks Karim. linio.tv is in the email. In the last part.
El oct 11, 2015 12:39 AM, "Karim Mezhoud" escribió:
> Hi,
> omit unlist and test. otherwise you can use apply function.
>
> draft:
>
> df1 <- apply(linio.tv, 1, function(x) strsplit(x[,idproductio],
> "[^A-Z0-9-]+"))
Hi Boris,
I've modified a little the for loop to catch the IDs (if there is any)
otherwise to put NAs. This is for another data set.
for (i in 1:nrow(linio.tv)) {
v <- unlist(strsplit(linio.tv$producto[i], "[^A-Z0-9-]+")) #
isolate tokens
if(any(grep("[A-Z][0-9]", v))) {
David answered most of this. Just a two short notes inline.
On Oct 10, 2015, at 12:38 AM, Omar André Gonzáles Díaz
wrote:
> David, Boris, so thankfull for your help. Both approaches are very good. I
> got this solve with David's help.
>
> I find very insteresting
I think you are going into the wrong direction here and this is a classical
example of what we mean by "technical debt" of code. Rather than tell to your
regular expression what you are looking for, you are handling special cases
with redundant code. This is ugly, brittle and impossible to
On Oct 9, 2015, at 4:21 PM, Boris Steipe wrote:
> I think you are going into the wrong direction here and this is a classical
> example of what we mean by "technical debt" of code. Rather than tell to your
> regular expression what you are looking for, you are handling special cases
> with
Thank you, David. You put me in the right direction.
At the end, I've used a lot of lines, to my taste, for this task.
Is there a more elegant way, of doing this?
ripley.tv$id <- sub("(.*)( [0-9]{2}[a-z]{1}[0-9]{4})(.*)", "\\2",
ripley.tv$producto,
On Oct 9, 2015, at 1:50 PM, Omar André Gonzáles Díaz wrote:
> David,
>
> this is a working case. I know that all cases for ID are not covered with my
> current code.
>
> The question is:
>
> ID stars as NAs.
>
> 1.- How to extract 1 type of ID, and keep the rest of entries as they are.
>
On Oct 9, 2015, at 2:48 PM, Omar André Gonzáles Díaz wrote:
> Thank you, David. You put me in the right direction.
>
> At the end, I've used a lot of lines, to my taste, for this task.
>
> Is there a more elegant way, of doing this?
There are conditional capture-classes in rexex in addition
On Oct 9, 2015, at 12:59 PM, Omar André Gonzáles Díaz wrote:
> I need to extract an ID from the product column of my df.
>
> I was able to extract the ids for some scenearios, but when applying my
> code for the next type of ids (there are some other combinations), the
> results of my first
David,
this is a working case. I know that all cases for ID are not covered with
my current code.
The question is:
ID stars as NAs.
1.- How to extract 1 type of ID, and keep the rest of entries as they are.
2.- Then keep the first extraction, and search for second type of ID.
3.- An so on
On Oct 9, 2015, at 9:38 PM, Omar André Gonzáles Díaz wrote:
> David, Boris, so thankfull for your help. Both approaches are very good. I
> got this solve with David's help.
>
> I find very insteresting Bori's for loop. And I need a little help
> understanding the regex part on it.
>
> - The
David, Boris, so thankfull for your help. Both approaches are very good. I
got this solve with David's help.
I find very insteresting Bori's for loop. And I need a little help
understanding the regex part on it.
- The strsplit function: strsplit(ripley.tv$producto[i], "[^A-Z0-9-]+")
I
I need to extract an ID from the product column of my df.
I was able to extract the ids for some scenearios, but when applying my
code for the next type of ids (there are some other combinations), the
results of my first line of code got NAs.
ripley.tv$id <- sub("(.*)(
Dear group,
Here is an object:
z -
c(LSCPos100415.csv, LSCPos100416.csv, LSCPos100419.csv,
LSCPos100420.csv, LSCPos100421.csv, LSCPos100422.csv,
LSCPos100423.csv,
LSCPos100426.csv, LSCPos100427.csv, LSCPos100428.csv,
LSCPos100429.csv,
LSCPos100430.csv, LSCPos100503.csv, LSCPos100504.csv,
Am 14.05.2010 12:10, schrieb arnaud Gaboury:
Dear group,
Here is an object:
z -
c(LSCPos100415.csv, LSCPos100416.csv, LSCPos100419.csv,
LSCPos100420.csv, LSCPos100421.csv, LSCPos100422.csv,
LSCPos100423.csv,
LSCPos100426.csv, LSCPos100427.csv, LSCPos100428.csv,
LSCPos100429.csv,
Of course this helps!
I didn't noticed the difference between sub and gsub.
TY
-Original Message-
From: Bernd Weiss [mailto:bernd.we...@uni-koeln.de]
Sent: Friday, May 14, 2010 12:23 PM
To: arnaud Gaboury
Cc: r-help@r-project.org
Subject: Re: [R] regex and sub
Am 14.05.2010
21 matches
Mail list logo