-
Issues with Filling Missing Values in Dictionaries
Hi,
I am new to q/kdb+ and working on the exercises (more specifically, the segment Dictionary mapping) for the module Dictionaries.
At present, I am uncertain about a few things even after spending much time pondering on them.
1.
newDict is:
Italy | "eu" Spain | "eu" Norway | "eu" Brazil | "sa" United States| "us" Yemen | "as" Mexico | "sa" Albania | "eu" Japan | "as" Australia | ""
The question requires us to fill in any missing values in newDict to “na”.
I tried “na”^newDict but it results in evaluation error: length. After reading the documentation for the fill operator ^, I am still unable to understand why and do not know if it is even possible to use this operator in this case.
(The solution provided is newDict[where 0=count each newDict]:enlist”na”. )
2.
To better understand the solution provided, I created a dictionary myDict:
1| "eu" 2| "" 3| "us" 4| ""
I noticed that myDict[where 0=count each myDict]:enlist”na” results in evaluation error: length.
It works only if there is one missing value in myDict but not more which I do not understand why.
(This means if newDict (in 1.) had more than one missing value, the solution provided would not work.)
myDict[where 0=count each myDict]:(“na”;”na”) works. However, I am unable to find an efficient way to do so if myDict has numerous associations and many missing values.
3.
My guess as to why the fill operator ^ does not work for both newDict and myDict is that the values are strings.
I created one more dictionary mySecondDict:
col1| col2| 5 6 col3|
99^mySecondDict works and I get:
col1| 99 99 99 col2| 99 5 6 col3| 99 99 99
However, I am uncertain if my guess is correct.
I would really appreciate any assistance with these issues.
Thank you very much.
Log in to reply.