Search code examples
kdb

How do I adds a substring to every column in kdb


My current columns in kdb is (Time;Buy;Sell). What should I do to change my column names to (Time_hist;Buy_hist;Sell_hist)?

Thank you!


Solution

  • Following expression will append "_hist" to all column names

    (`$(string cols t),\:"_hist") xcol t
    

    where t is table.

    1. string cols t - retrieves all column names and converts them to strings
    2. (string cols t),\:"_hist" appends "_hist" to each column name on the left
    3. colnames xcol t renames table column names. See xcol for more details