0
$\begingroup$

I want to return a list of all lists with elements in a single first list styled if it meets a condition so that it stands out from other lists. My attempt at this only returns all data with no row styled. Here is what i have...

eqs = {eqn = S'[t] + .1 S[t] == 0, ic = S[0] == 30000};
sol = DSolve[eqs, S[t], t][[1, 1, 2]];
raw = Table[{t, sol}, {t, 0, 15}];
yr = Select[raw, #[[2]] < 8000 &, 1][[1, 1]];
data = MapAt[PaddedForm[#, {5, 2}] &, raw, {All, 2}];
Map[Style[#, Bold, Green] &, data[[yr + 1]]] (* proof of concept *)
data = Replace[data, 
data[[yr + 1]] -> Map[Style[#, Bold, Green] &, data[[yr + 1]]]]
$\endgroup$
5
  • 1
    $\begingroup$ Map[Style[#, Bold, Green] &, data[[yr + 1]]]? $\endgroup$ Commented May 4, 2020 at 1:54
  • $\begingroup$ thank you. that solves the curly brackets not getting highlighted when applied as you suggested but when inserted in data = Replace[...] it returns the data with no row highlighted. $\endgroup$ Commented May 4, 2020 at 2:02
  • $\begingroup$ Did the answer I posted do what you want? Not sure what you mean by "return all lists". $\endgroup$ Commented May 4, 2020 at 2:04
  • $\begingroup$ @RohitNamjoshi in case you missed it i had edited my comment. here is the edited comment: thank you. that solves the curly brackets not getting highlighted when applied as you suggested but when inserted into data = Replace[...->Map[...]] it returns the original data with no row highlighted. $\endgroup$ Commented May 4, 2020 at 2:07
  • $\begingroup$ Added image to the answer. Do you see something different? $\endgroup$ Commented May 4, 2020 at 2:12

1 Answer 1

1
$\begingroup$

Is this what you are looking for?

data // ReplacePart[yr + 1 -> Map[Style[#, Bold, Green] &, data[[yr + 1]]]]

enter image description here

$\endgroup$
2
  • $\begingroup$ thank you. that worked. i have just one question. how could i have written it without postfix notation (//ReplacePart[...])? $\endgroup$ Commented May 4, 2020 at 2:21
  • $\begingroup$ I used the operator form of ReplacePart. I find it easier to understand and edit expressions in postfix form rather than deal with deeply nested square brackets. ReplacePart[data, yr + 1 -> Map[Style[#, Bold, Green] &, data[[yr + 1]]]]. $\endgroup$ Commented May 4, 2020 at 2:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.