1
$\begingroup$

I am working to take a large manipulator I have built and generalize it, but I keep running into some variable assignment issue.

I made a short example of my issues below:

Set up:

dataSet = Dataset[    {
    <|"first" -> 1,
     "second" -> 2, "third" -> 3|>,
    <|"first" -> 3, "second" -> 6, "third" -> 9|>
    }]; 

featureofInterest = "first";

foo2 = ToExpression["#" <> featureofInterest]; 

This works:

Manipulate[  foo = dataSet[Select[#first > 2 &]];  foo[All, var],  {var, {"first", "second", "third"}}]

But this does not:

Manipulate[  foo = dataSet[Select[foo2 > 2 &]];  foo[All, var],  {var, {"first", "second", "third"}}]

Even though:

foo2 == #first
True

Any thoughts on what I am doing wrong?

$\endgroup$
  • $\begingroup$ #name is just a shortcut to #["name"] for association, so you may use Manipulate[foo = dataSet[Select[#[featureofInterest] > 2 &]]; foo[All, var], {var, {"first", "second", "third"}}] $\endgroup$ – egwene sedai Jan 23 at 18:53
  • $\begingroup$ reference.wolfram.com/language/ref/Slot.html $\endgroup$ – egwene sedai Jan 23 at 18:53
  • $\begingroup$ Thanks @egwenesedai!! $\endgroup$ – user60143 Jan 23 at 19:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.