3

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?

Mitchell Kaplan
  • 3,696
  • 22
  • 34
  • Try dataset[Select[Key[a] < 5 &]] – m_goldberg Jun 25 '15 at 20:53
  • 2
    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. – m_goldberg Jun 25 '15 at 21:01
  • @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. – Mitchell Kaplan Jun 25 '15 at 21:26
  • 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. – m_goldberg Jun 25 '15 at 21:36
  • @m_goldberg - I used the example in Help. I tried SquareOne's suggestion and it did work - although I thought I had tried that one before. I appreciate the help. Thanks. – Mitchell Kaplan Jun 26 '15 at 01:49
  • 2
    It's worth bearing in mind that the string quoted keys behaviour is has changed over the 10.0.x and 10.x releases – Gordon Coale Jun 26 '15 at 06:18
  • @GordonCoale I didn't know that. Can you point me to information on those changes? – Mitchell Kaplan Jun 26 '15 at 11:45
  • @MitchellKaplan see here. That was on 10.0 as I recall. – Gordon Coale Jun 26 '15 at 12:18

1 Answers1

4

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

SquareOne
  • 7,575
  • 1
  • 15
  • 34