How to print and style mathematica results in text - printing

How can I print a line of text with the results of some variable and still edit the font size and font color? Something like this:
Style[
"The equation result was ", Returns,
"% running from ",DateString[TableDate[[1]],
{"MonthName", " ", "DayShort", ", ", "Year"}]
, 15, Red]
I wanted something like:
The equation result was 35% running from January 15, 2000
But in red and in a bigger font size! Is it possible?
Thanks

Returns = 35;
TableDate = {{2000, 1, 15}};
Style[StringJoin["The equation result was ", ToString#Returns,
"% running from ", DateString[TableDate[[1]],
{"MonthName", " ", "DayShort", ", ", "Year"}]], 20, Red]

Related

ArrayFormula - Number Partitioning row wise - Attempt to use a single column formula for all rows

Ref link
Problem description. From a CSV string ("10,13,25,17") each number is partitioned X times such that sum is equal to the original number. Only interested in the average number(s).
Eg: 10 partition 3 = { 3,3,4 }, 15 partition 2 = { 7,8 }, 10 partition 2 = { 5, 5 }
So the input to output (JOIN-ed) looks like ==>
Part("22,25,30",12) = "1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,2,2,2,2,2,2,3,3,3,3,3,3"
I have successfully created the ArrayFormula for above. But am stuck on how to apply it to a whole column (vertically). Any ideas? (recently someone in StackOverflow introduced me to QUERY header smush - but still stuck on this).
On a separate note - I wonder if "Named Formulas" or "Formula Aliases" are ever coming to Google Sheets. Reusing formula components will be a life saver with these huge ArrayFormulas. And yes - I have sent this query to Google many times over a few years.
Horizontal query smash (or is it vertical?...) to the rescue (formula is in D10):
=ARRAYFORMULA(
IF(
A10:A = "",,
REGEXREPLACE(
TRANSPOSE(QUERY(TRANSPOSE(
IF(
SPLIT(A10:A, ",") = "",,
REPT(
INT(SPLIT(A10:A, ",") / Months) & ",",
Months - MOD(SPLIT(A10:A, ","), Months)
)
& REPT(
INT(SPLIT(A10:A, ",") / Months) + 1 & ",",
MOD(SPLIT(A10:A, ","), Months)
)
)
),, 10^7)),
"\s+|,\s*$",
)
)
)
Notice that you original solution was simplified and used in here. Simplified original solution is in B3:
=REGEXREPLACE(
CONCATENATE(
ArrayFormula(
REPT(
INT(SPLIT(A2, ",") / Months) & ",",
Months - MOD(SPLIT(A2, ","), Months)
)
& REPT(
INT(SPLIT(A2, ",") / Months) + 1 & ",",
MOD(SPLIT(A2, ","), Months)
)
)
),
",$",
)

How can I create a range display from a list of non consecutive numbers?

I made a bash script to display numbers in range and I wonder if it's possible to do the same in Sheets without scripting.
I got in a column (let's say A) a list of numbers, for example :
001
002
004
012
013
014
...
and I have a variable prefix in a cell (let's say B1="PREFIX")
Is there a way to display the result as below :
PREFIX001-PREFIX002
PREFIX004
PREFIX012-PREFIX014
...
Thank you by advance for your help !
Could be done. For example A3:A range has the numbers, B1 will be the prefix and B3:B will have the resulting rows.
The formula is only (as it is an array formula) in B3:
=ARRAYFORMULA(
TRANSPOSE(SPLIT(
REGEXREPLACE(
REGEXREPLACE(
TEXTJOIN(
",",
True,
IF(
NOT(ISNUMBER(A3:A)),
"",
IF(
NOT(ISNUMBER({""; OFFSET(A3:A, 0, 0, ROWS(A3:A) - 1)}))
+ NOT(ISNUMBER({A4:A; ""}))
+ ( ISNUMBER({""; OFFSET(A3:A, 0, 0, ROWS(A3:A) - 1)})
* (A3:A <> {""; OFFSET(A3:A, 0, 0, ROWS(A3:A) - 1)} + 1))
+ ( ISNUMBER({A4:A; ""})
* (A3:A <> {A4:A; ""} - 1)),
TEXT(A3:A, "00#"),
""
)
)
& IF(
ISNUMBER({A4:A; ""})
* (A3:A = {A4:A; ""} - 1),
"-",
""
)
),
"(?:-,)+",
"-"
),
"\d+",
B1 & "$0"
),
","
))
)
Here is a sample sheet with step by step description of the solution: link.
#kishkin
Thank you so much for taking the time to do that ! I made a copy to check it, that's very kind of you !
I made mine with multiple columns but in the nasty way (I'm quite new with Sheets but I love it so far) :
to group consecutive numbers :
=IF(CNUM(V2)=CNUM(V1)+1,IF(REGEXMATCH(W1,"-"),LEFT(W1,CHERCHE("-",W1)-1)&"-"&V2,V1&"-"&V2),V2)
to replace lonelies that are part of a range :
=IF(LEFT(W3,2)=LEFT(W2,2),0,W2)
Split the range to calculate range value later :
=SPLIT(X2,"-")
To calculate the range except for 0 values :
=IF(Z2-Y2+1<0,1,Z2-Y2+1)
To remove all the 0 so only the ranges remain :
=filter(X2:X,X2:X>0)
To align the totals with the ranges (useful for group reservations for a project)
=filter(AA2:AA,X2:X>0)
After that, it's just adding the prefix and add some text (sorry for the french).
As I told you it's not as sexy as your solution ^^

How to see the +/- change in rolling average between two cells

As you can see from my picture, I have a list of bowling scores and some running averages. The issue I cannot seem to solve is I would like to be able to see the change in average between a game and the previous game. If the average goes down, it would say -1.2% for example or +2.1% if it goes up. I would really like negative averages to be in red and positive ones in green if that is possible.
Here is a copy of my sheet with the desired output in column G.
first you will need running average:
=ARRAYFORMULA(QUERY(TRANSPOSE(QUERY(TRANSPOSE(IF(ISNUMBER(
ARRAY_CONSTRAIN(SPLIT(SORT(REPT("♦ ", ROW(INDIRECT("A1:A"&COUNTA(A2:A)))-1), 1, 0)&
"♦"&TEXTJOIN("♦", 1, C2:C), "♦"), 999^99, COUNTA(A2:A))),
ARRAY_CONSTRAIN(SPLIT(SORT(REPT("♦ ", ROW(INDIRECT("A1:A"&COUNTA(A2:A)))-1), 1, 0)&
"♦"&TEXTJOIN("♦", 1, C2:C), "♦"), 999^99, COUNTA(A2:A)), )),
"select "&TEXTJOIN(",", 1, IF(LEN(A2:A),
"avg(Col"&ROW(A2:A)-ROW(A2)+1&")", ))&"")),
"select Col2", 0))
then you can do:
=ARRAYFORMULA(IF(A2:A<>"", {0; (INDIRECT("F2:F"&ROWS(F3:F))-F3:F)*-1}, ))
and finally color format it:
UPDATE:
with new functions, there is a new method...
average = sum / count therefore we can run running total / cumultative sum:
=SCAN(, A2:A20, LAMBDA(x, y, (x+y)))
and then just divide by sequence to get the running average:
=INDEX(SCAN(, A2:A20, LAMBDA(x, y, (x+y)))/(ROW(A2:A20)-1))
and to get the difference between x and x+1 cells:
={0; MAP(B2:B19, LAMBDA(z, OFFSET(z, 1, )-z))}
and the final touch:
0[=0][black]; -0.00###[<0][red]; 0.00####[color 50]
or in one go:
={0; INDEX(ARRAY_CONSTRAIN({QUERY(
MAP(SCAN(, A2:A20, LAMBDA(x, y, (x+y))), ROW(A2:A20)-1,
LAMBDA(a, b, a/b)), "offset 1", ); ""}-
MAP(SCAN(, A2:A20, LAMBDA(x, y, (x+y))), ROW(A2:A20)-1,
LAMBDA(a, b, a/b)), ROWS(A2:A20)-1, 1))}
You get the change percentage using: =ROUND((C3-C2)/C2*100,2) in G3:G20.
Check:
For going down from 145 to 123 this returns (with no rounding) -15.17241379.
145 + (145 * -15.17241379 / 100) = 123
For the colouring:
Select the cells G3:G20.
Go to -> Format -> Conditional formatting -> Format rules -> Format cells if… -> Greater than -> 0 -> Formatting style
-> [Down arrow next to letter A] -> [Pick your colour]
-> [Down arrow next to (bucket with) fill colour] -> [None]
PS: For the running average you can use: =AVERAGE(C$2:C2) in F2:F20.
Please comment, if and as this requires adjustment / further detail.

combining these two lua formatting lines into one

is there any way to combine these last two formatting lines of code into one?
str = "1, 2, 3, 4, 5, "
str = str:gsub("%p", {[","] = " >" }) -- replaces ',' with '>'
str = string.sub(str, 1, #str - 2) --removes last whitespace + comma
Thanks in advance :)
str = "1, 2, 3, 4, 5, "
str = str:sub(1, #str-2):gsub("%p", {[","] = " >" })
This will do what you want it to do.
Egor's is a bit more elegant, though:
str = str:gsub(',',' > '):sub(1,-3)

problem with using statement in gnuplot

I'm trying to plot some data. I have a file looking like this
50 11 1 1
100 29 1 6
200 62 4 26
300 104 9 39
and a plotfile
# Vergleich
set terminal png
set output "streetsegments.png"
set datafile separator "\t"
set yrange [0:105]
set ytics ("0" 0, "10" 10, "20" 20, "30" 30, "40" 40, "50" 50, "75" 75, "100" 100)
set xtics ("50" 50, "100" 100, "200" 200,"300" 300)
set xrange [0:300]
set xlabel "Error in meters"
set ylabel "Street segments"
set notitle
plot "segments" using 1:2 t 'foo' with lp, \
"segments" u 1:3 t 'bar' with lp, \
"segments" u 1:4 t 'baz' with lp
But when plotting, it doesn't show anything besides the titles of the lines, but no lines themselves are drawn. Any idea, why this doesn't work?
When only plotting on column (by not using the "using"-statement ) it works just fine.
Works for me. Try again removing the set datafile separator "\t" line and see if that solves it.

Resources