Hello,
Noob question...
I have a column with a unique identifier (UID) for certain types objects, for instance {'cats', 'dogs', 'birds'}. Each UID has multiple rows associated with it, which I have captured in an associative array.
Example: aa = { 'cats' => [1, 2, 3], 'dogs' => [4, 5, 6], 'birds' => [7, 8, 9] }
For each UID, all rows associated, I need to set a different column (col2) to a single value.
For example: For UID 'cats', rows 1, 2 & 3, in col2, need to be set to 'likes napping'.
- I know of the << Set all values function, but that copies a single value for all rows in a column.
- If I use dt:col 2[ aa[ 'cats' ] ] = 'likes napping', a L-value error will occur, which informs me I need a matrix of values equal to the number rows, so each row can be assigned that value.
- Or, I can use a for loop nested in a for loop to assign values where I need.
This all seems clunky though. There must be a better way.
Here are the 2 associative arrays:
- { UID => [rows] }
- { UID => value }
Learning every day!