3
$\begingroup$

I've tended to not put quotes around the names of my Key when making Associations. For example:

devToaAssoc = AssociationThread[{Flag, ALOB, LI}, {True, #[[1]], #[[3 ;; 12]]}] & /@ dataIn;

However I've run into problems in trying to do certain things. For example, in the Dataset section of Help, there is the following example:

dataset[Select[#a < 5 &]] 

If I change the example so that the key is a, but without quotes, I can't get a Select to work. I've tried a number of things, for example, using Key[a], and without the &. Also I've noticed that the Dataset display is quite different if I remove the quotes from the Key A.

I have 2 questions. First, is there some way I should be able to get that Select statement to work if my key doesn't have quotes? Second, are there any other issues I should be aware of that might make NOT using quotes a bad idea?

$\endgroup$
8
  • $\begingroup$ Try dataset[Select[Key[a] < 5 &]] $\endgroup$
    – m_goldberg
    Jun 25, 2015 at 20:53
  • 2
    $\begingroup$ I'm not sure I'd go so far as to call using symbols as keys a bad idea, but I get the sense from all the various examples in the docs on the use of associations that Wolfram is encouraging us to use string keys rather symbol keys. $\endgroup$
    – m_goldberg
    Jun 25, 2015 at 21:01
  • $\begingroup$ @m_goldberg I tried your example and I wind up with what appears to be an empty result. It says 0 rows and doesn't show anything. I also see that most, but not all, of the examples use string keys. I also don't know what would happen if I were to use one of those symbols elsewhere. Probably nothing good. $\endgroup$ Jun 25, 2015 at 21:26
  • $\begingroup$ Since you didn't provide a means for me to build dataset, it's impossible for me to investigate what went wrong with dataset[Select[Key[a] < 5 &]]. You need to provide real data if you want more than vague advice. $\endgroup$
    – m_goldberg
    Jun 25, 2015 at 21:36
  • 2
    $\begingroup$ It's worth bearing in mind that the string quoted keys behaviour is has changed over the 10.0.x and 10.x releases $\endgroup$ Jun 26, 2015 at 6:18

1 Answer 1

4
$\begingroup$

This seems to work:

Given for example

dataset = Dataset[{
    <|AZ -> 1, "b" -> "x", "c" -> {1}|>,
    <|AZ -> 2, "b" -> "y", "c" -> {2, 3}|>}];

then

dataset[Select[#[AZ] > 1 &], "b"]

returns

enter image description here

$\endgroup$

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.