Forum Replies Created

  • baichen

    Member
    February 2, 2023 at 12:00 am in reply to: Challenge 1 – Triangle Font
    q){b:first x+1;b#x+1}[8;1] 
    1 
    2 2 
    3 3 3 
    4 4 4 4 
    5 5 5 5 5 
    6 6 6 6 6 6 
    7 7 7 7 7 7 7 
    8 8 8 8 8 8 8 8
  • baichen

    Member
    August 23, 2022 at 12:00 am in reply to: Unpack nested column in table

    select a:a ,b1:b[;0],b2:b[;1],b3:b[;2] from t

    a b1 b2 b3
    ----------
    1 4  5  6 
    2 6  12 23
    3 12 36 14
  • baichen

    Member
    August 23, 2022 at 12:00 am in reply to: Unpack nested column in table

    I guess you mean:

     

     

    (flip enlist[`a]!enlist[t `a]),'flip `b1`b2`b3!flip t `b 
    a b1 b2 b3 
    ---------- 
    1 4 5 6 
    2 6 12 23 
    3 12 36 14

     

     

  • baichen

    Member
    August 22, 2022 at 12:00 am in reply to: rolling linear regression in q

     

    tData:([]y:10?100.0;x1:10?10.0;x2:10?20.0;x3:10?30.0;const:1.0) 
    tData 
    y x1 x2 x3 const 
    ------------------------------------------- 
    8.226874 2.037285 8.538354 16.01854 1 
    51.32018 7.757617 15.40955 28.16125 1 
    49.47829 0.6938325 0.3188056 9.083402 1 
    86.65565 4.101914 7.146077 13.34548 1 
    64.14975 2.337549 0.5094767 13.24347 1 
    90.82711 7.125845 13.76178 21.80396 1 
    97.96094 1.392257 12.75511 29.98824 1 
    30.77491 2.701876 0.7691273 22.29986 1 
    36.52273 6.357182 17.94471 7.113864 1 
    95.91177 7.771303 15.87103 17.01243 1 
    
    rolling:{[w;t] (w-1)_({ 1_x,y }[w#delete from t;t])} 
    fn:{[t;Y;X] 
           yx:enlist t[Y] mmu flip t[`const,X];
           xx:x mmu flip[x:t[`const,X]];yx lsq xx} 
    fn[;`y;`x1`x2`x3] each rolling[5;tData] 
    49.22355 4.14351 -3.200252 -0.6170487 
    30.90215 9.65294 -4.097335 0.03631143 
    41.24432 -5.843066 0.4397651 1.026252 
    14.49142 -2.988273 -0.3123183 2.138712 
    6.81604 -5.333931 1.68819 1.800037 
    -18.19828 -2.163089 3.582677 1.640662

     

     

     

    It returns rows of lists of betas with rolling window:5

     

  • baichen

    Member
    August 22, 2022 at 12:00 am in reply to: rolling linear regression in q

    Wrapped them into function:

    tabData:([]y:10?100.0;x1:10?10.0;x2:10?20.0;x3:10?30.0;const:1.0); 
    main:{[n;y;xs;tab] rolling:{[w;t] (w-1)_({ 1_x,y }[w#delete from t;t])}; 
    fn:{[t;Y;X] 
          yx:enlist t[Y] mmu flip t[`const,X];
          xx:x mmu flip[x:t[`const,X]];yx lsq xx}; 
          fn[;y;xs] each rolling[n;tab] } 
    betas:main[5;`y;`x1`x2`x3;tabData]

     

     

  • baichen

    Member
    August 19, 2022 at 12:00 am in reply to: licence error: k4.lic

    for default installation, you should put the kc.lic file in your $HOME/q directory :

    baichen@MacProM1:~/q$ ls

    kc.lic m64/ q.k

     

  • baichen

    Member
    August 10, 2022 at 12:00 am in reply to: null first n terms for mavg

    To set value in a list, we can use @

    n:2
    @[3 mavg a;til n;:;0n]
    0n 0n 1 2 3 4 5 6 7 8

  • baichen

    Member
    August 6, 2022 at 12:00 am in reply to: Key value pairs in dictionary, and how to retrieve them given one?

    you also can use where clause, which return all keys that have duplicates:

    q)dic:`a`b`c`d!1 2 3 1
    q)where dic=1
    `a`d
    
    
  • baichen

    Member
    July 30, 2022 at 12:00 am in reply to: If conditions $ vs ?

    ? can be used in vector-based condition . For example:

    ?[101b;`a;`b]
    `a`b`a

    $ is used in single condition :
    $[1b;`a;`b]
    `a