# Unix-like reference to parent and root Association?

Is there a syntax or function to reference parent and root when querying nested Associations similar to Unix' ".." and "/", eg "cd ../../mydir". ?

Here's a typical application of the root construct. Given a nested dataset:

ds = <|  "study" -> <|   "all"  -> <|"n" -> 223., "Median" -> 18.5 |>|>,
"bySite" -> <|   "VASD" -> <|"n" -> 107., "Median" -> 20.40|>,
"UCSD" -> <|"n" -> 116., "Median" -> 16.5 |>|>,
"bySpeciality" -> <|"Primary" -> <|"n" -> 127., "Median" -> 17.8 |>,
"Specialty" -> <|"n" -> 96. , "Median" -> 19.5 |>|>|> // Dataset


(Dataset is only used here for formatting convenience)

using ds["study","all","n"] as denominator, the query is to convert all values of the instances "n" to ratios:

   ds[All, All, #/ds["study", "all", "n"] &]


But how can it be used in a query without reference to ds? For example, would like to use something like RootAssociation

ds // Query[All, All, {"n" -> (#/RootAssociation["study", "all", "n"] &)}]


ParentAssociation would work in a similar way

• In general you'll be more likely to get responses if you use code that others can immediately evaluate, and simplify your examples as far as you can. The RightCompositions make the code harder to read and understand for someone who isn't familiar with it already. – user6014 Nov 23 '16 at 14:50
• @user6014, re the first point, I'll replace w/ a self-contained version. Re RightComposition - I think it makes code easier to read, it's just an infix version. – alancalvitti Nov 23 '16 at 17:54
• @user6014, I simplified the example to make it more readable. – alancalvitti Nov 23 '16 at 20:08
• What about Function[RootAssociation, RootAssociation//Query[All, All, {"n" -> (#/RootAssociation["study", "all", "n"] &)}] ] isn't necessarily better but you can define queries separately. – Kuba Nov 23 '16 at 20:17
• @Kuba, I would consider that cheating, as you might as well write: ds // Function[ds, ds // Query[All, All, {"n" -> (#/ds["study", "all", "n"] &)}]] - maybe a version using UpValues? – alancalvitti Nov 23 '16 at 20:24