Can we add support for negative units on cut() and probably others?
rfuentealba
New Altair Community Member
Well, today I had an interesting, super simple case. I had the following strings:
Enero 2016
Febrero 2016
Marzo 2016
Abril 2016
...
Those are strings that define "periods" (months, as "enero" is January, etc...) but not exactly dates (as this is the name of the period for an invoice, and therefore it's treated like a categorical variable, but the actual reading date for January 2016 could be 30 December 2015 and the emission date could be 2 February 2016, so there is no need to use a date expression to define it).
I wanted to obtain just the portion of the string that says "2016" at the end with the "Generate Attributes" operator (there is plenty of ways to do that, but I kinda like to use some programming to generate a new attribute). To my dismay, the syntax for cut does not allow negative numbers, so I couldn't do the following:
cut("Periodo", 0, -4)
I think this is very specific, might not be relevant, and it can make the bottom of the priority list of features but... IDK, can this be added? it's just that I'm used to have these things in other programming languages, I thought it can just be a nice thing to have.
All the best,
Rod.
Tagged:
1
Best Answers
-
Hi @rfuentealba,
why cant you just use suffix("Periodo",4)? This would give you the right result.
Sure you may want to do:
cut("att",-10,-4)
at some point. Which needs clever combination of prefix and suffix, but would work.
Best,
Martin1 -
I usually do "suffix(Periodo,length(Periodo)-index(Periodo," ")-1)" or similar. You can add a parse if you want it to be numerical.
1
Answers
-
The negative offset syntax is quite common in other expression languages to refer to "count from the end". I like this idea very much.1
-
Hi @rfuentealba,
why cant you just use suffix("Periodo",4)? This would give you the right result.
Sure you may want to do:
cut("att",-10,-4)
at some point. Which needs clever combination of prefix and suffix, but would work.
Best,
Martin1 -
I usually do "suffix(Periodo,length(Periodo)-index(Periodo," ")-1)" or similar. You can add a parse if you want it to be numerical.
1 -
Thanks to both, I didn't know about suffix()!I appreciate the timely answers too.All the best,Rod.2