calculate an exponent from another column - amazon-dynamodb

Does anyone know if DynamoDB supports calculating exponents in an UpdateExpression?
I know I can add or subtract from a column, but that seems to be the mathematical limit on updates that I can find.
I am trying to take and existing column value, take 2 to the power of that column value, and then update a second column.
Thanks

Unfortunately, you can only add/subtract. From the docs for Update Expressions:
Incrementing and Decrementing Numeric Attributes
You can add to or subtract from an existing numeric attribute. To do this, > use the + (plus) and - (minus) operators.
You'll need to perform the exponent function in your application code after reading the item.

Related

Pentaho Formula

I am new to Pentaho, so please be gentle.
I am, perhaps naively, wanting to use a Formula to convert a six-character string in the form YYYYMM to the date representing the final day of that month.
I imagine doing this step by step using successive lines of the Formula: checking that the string is of the correct length and, if so:
extracting the year and converting it to integer (with error checking)
extracting the month and converting it to integer (also with error checking)
converting ([year], [month], 1) to a date (the first of the month)
adding a month
subtracting a day
Some of those steps may be combined but, overall, it relies on a succession of steps to achieve a final result.
Formula does not seem to recognise the values achieved along the way though, at least not by enclosing them in square brackets as you do with fields from previous objects in the mapping.
I suppose I could have a series of Formula objects one after the other in the mapping but that seems untidy and inefficient. If a single Formula object cannot have a series of values defined on successive lines, what is the point of even having lines? How do I use a value I have defined on a previous line?
The formula step isn’t the best way to achieve that. The resulting formula will be hard to read and quite cumbersome.
It’s better (and faster) to use a calculator step. A javascript step can also be used, and it will be easier to read, but slower (though that probably won't be a major issue).
So, one way forward is to implement this on a calculator step:
Create a copy of your string field as a Date
Create 2 constant fields: 1 and -1
Add 1 month to the date field
Subtract 1 day to the result
Create a copy of the result as a string.
See screenshot:

What sorting algorithm does dplyr's arrange function use?

I have a dataset where we are bringing in a dataframe of values, and assigning each of the values a number 1-5. We're then sorting these values according to this column using dplyr::arrange.
In looking through the resulting data, it's clear that, aside from being ordered by the numbers in the 1-5 column, the original order the rows came in impacts the final order. However, I can't figure out what's impacting the order of rows within each group.
To this end, I've been trying to find the sorting algorithm that dplyr's arrange function uses - however, I can't find it anywhere here or in the documentation. Any help would be appreciated
The documentation doesn't tell you, and doesn't guarantee that order is preserved within ties. That means you shouldn't assume anything about the behaviour within ties.
All you should assume is that things are ordered as the documentation says they will be. If that is violated, it's a bug. If the documentation doesn't say what will happen, then you should assume that whatever happens today may be different tomorrow.
It's easy enough to make any sort into a stable sort (that maintains the original ordering within ties). Just add an extra column containing the original position, and include it as the final column for breaking ties. For example,
dplyr::arrange(mtcars, carb)
doesn't say anything about the order within rows that have the same value of carb. But
dplyr::arrange(data.frame(i = 1:nrow(mtcars), mtcars), carb, i)[-1]
guarantees that the original order is kept within carb values.
The code shows it eventually calls base::order with the default method, so:
method: the method to be used: partial matches are allowed. The
default (‘"auto"’) implies ‘"radix"’ for short numeric
vectors, integer vectors, logical vectors and factors.
Otherwise, it implies ‘"shell"’. For details of methods
‘"shell"’, ‘"quick"’, and ‘"radix"’, see the help for ‘sort’.
Though, it does pass through vctrs::vec_proxy_order first - not sure it that matters.

How to calculate average annual salary in libreoffice calc

I have salary data table from 10 years period. Every column has properly set data type (date for "B", number for "C" and "E".
I'm trying to write a formula to calculate average salary for every year. In column "E" I've manually entered all possible years and in column "F" should be an yearly average, according to year from "E".
So, my best try is this formula: =AVERAGEIF(YEAR(B2:B133);"="&E2;C2:C133)
Trying so calculate an average from column C, where year in date from column B equals a year in column E
But all I get is an error Err:504. Figured out, that problem is in YEAR(interval) part, but can't get what exactly...
Can someone point that out?
Thank you!
There are actually many possibilities to solve this.
#JvdV answer;
using an array formula with #JvdV solution;
using an array formula with a combination of AVERAGE() and IF();
using the SUMPRODUCT() function;
and surely many other solutions that I don't know about!
Please beware: I use , instead of ; as formula separator, according to my locale; adapt to your needs.
A side note on "array formulas"
This kind of formulas are applied by mandatory pressing the Ctrl + Shift + Enter key combination to insert them, not only Enter or Tab or mouse-clicking elsewhere on the sheet.
The resulting formula is shown between brackets {}, which are not inserted by the user but are automatically shown by the software to inform that this is actually an array formula.
More on array formulas i.e. on the LibreOffice help system.
Usually you cannot drag and drop array formulas, you have to copy-paste them instead.
Array formula with #JvdV solution
The solution of JvdV could be slighly modified like this, and then inserted as an array formula:
=AVERAGEIFS(C$2:C$133,YEAR($B$2:$B$133),"="&E2)
When you insert this formula with the Ctrl + Shift + Enter key combination, the software puts the formula into brackets, so that you see it like this: {=AVERAGEIFS(C$2:C$133,YEAR($B$2:$B$133),"="&E2)}
You cannot simply drag the formula down, but you can copy-paste it.
Array formula with a combination of AVERAGE() and IF():
For your example, put this formula in cell F2 (for the year 2010):
=AVERAGE(IF(YEAR($B$2:$B$133)=E2,$C$2:$C$133))
When you insert this formula with the Ctrl + Shift + Enter key combination, the software puts the formula into brackets, so that you see it like this {=AVERAGE(IF(YEAR($B$2:$B$133)=E2,$C$2:$C$133))}
You cannot simply drag the formula down, but you can copy-paste it.
SUMPRODUCT() formula:
My loved one...
Plenty of resources on the web to explain this formula.
In your situation, this would give:
=SUMPRODUCT($C$2:$C$133,--(YEAR($B$2:$B$133)=E2))/SUMPRODUCT(--(YEAR($B$2:$B$133)=E2))
This one you can drag down to your needs.
Unfortunately AVERAGEIF() expects a range reference instead of a calculated array. Therefor it will error out. That's the theory at least for Excel, and I expect this to be the same for LibreCalc.
One way around it is using the AVERAGEIFS() function and check against first and last days of the year, for example:
=AVERAGEIFS(C$2:C$133;B$2:B$133;">="&DATE(E2;1;1);B$2:B$133;"<="&DATE(E2;12;31))
Drag the formula down.

How to add empty values in a vector, matrix, structure

I am trying to do some calculations where I divide two vectors. Sometimes I encounter a division by zero, which cannot take place. Instead of attempting this division, I would like to store an empty element in the output.
The question is: how do I do this? Can vectors have empty fields? Can a structure be the solution to my problem or what else should I use?
No, there must be something in the memory slot. Simply store a NaN or INT_MIN for integer values.

MS Access- Calculated Column for Distinct Count in Table Rather than a Query

I'd like to have a Calculated Column in a table that counts the instances of a concatenation.
I get the following error when inputting Abs(Count([concat])) as the column formula for the calculation: The expression Abs(Count([concat])) cannot be used in a calculated column.
Is there any other way to do it without doing a query? I'm pretty sure it can't be done but I figured I'd ask anyways since I didn't see any other posts about it.
No, and even if there was, you should create and use a query for this.
Besides, applying Abs on a count doesn't make much sense, as the count cannot be negative.

Resources