Baseball Formatting

I’d like to create some new string columns based on numeric columns in my data set. The new column needs to use traditional baseball formatting. That is, values less than one should appear with a decimal point followed by exactly three numbers. If the value is greater than one, the non-fractional part appears to the left of the decimal point as normal.

So, for example, 0.251 would become “.251” and 0.3 would become “.300”. A value like 1.1 would become “1.100”.

How might I do that with EasyDataTransform?

it might work with the Replace transformation and some regex expressions. Here one possible solution in a different manner.

image

baseball_formating.transform (3.5 KB)

If you are new in EDT, the $(1) in the if statement address the first column (by evident it is column name, too, so both would work) of the data table.

2 Likes

You can do it with 2 transforms:

baseball_formating-2.transform (2.4 KB)

This:

Replaces anything starting with “0.” with a “.”.

It is also possible to do it without regular expressions, but it is likely to take more transforms.

2 Likes

Thank you, that’s very straightforward. As I’ll do this many times across many future projects, is it possible to build reusable “subroutines” of transformation like that?

It is on the wishlist to be able to store ‘snippets’ of regular expressions and Javascript.

Until then you can ‘File>Save as’ a .transform as a template for a new .transform.