5
$\begingroup$

I have a dataset which are keyed on {"Item", "Hour of Day", "Value"}.

In the examples, I noticed that it is possible to apply functions using such as

Select[(#a > 1 &)] 

But what would the slot name be for my string values above? Is there a way to interrogate a dataset for its slots?

Should I simply avoid the issue and rename them if I wish to perform such operations?

$\endgroup$
2
  • $\begingroup$ Did you try #["Item"] and #Item as described in the docu? $\endgroup$ Commented Jul 19, 2014 at 18:01
  • 1
    $\begingroup$ @Karsten7. Thanks, that does it. If you had put this as an answer, then I would be happy to close the question. $\endgroup$ Commented Jul 19, 2014 at 18:11

2 Answers 2

13
$\begingroup$

The functionality of Slot(#) got extended in Mma version 10. As described in the documentation you can use

#["Item"] 

or

#Item 

to pick out the elements with the key "Item".

Edit:
As pointed out in the comment by @alancalvitti

#"Item" 

also works, as

#"Item" & // InputForm 

#Item &

and can be used for your second key:

#"Hour of Day" 
$\endgroup$
2
  • 3
    $\begingroup$ For keys with protected characters need quotes in the 2nd form above: #"SUBJECT_ID" $\endgroup$ Commented Jul 19, 2014 at 20:44
  • $\begingroup$ Quoted names are not documented for special characters (spaced cases for example). Nice Tip. +1 $\endgroup$ Commented Jul 19, 2014 at 21:24
1
$\begingroup$

If your keys are not strings, then it is a bit trickier, as Slot[keyname] does not seem to work. The only form I have managed to get working is, for example,

Select[Key[keyname][#] > 1 &][dataset] 
$\endgroup$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.