Trying to put something together to address a bug I introduced into brewscheme. The examples are related to the dataset used by the package (hence the reference). The help for this function reads:
I wanted to include an additional test/check to make sure the number passed by the end user would select the appropriate subset of records, but it looks like the selectindex() function returns void when the value is not found. I've tried wrapping the result in the missing() function, but that also failed to detect that the variable didn't contain any results. The reason for all of this is that I need analogous functionality to the levelsof command without sorting the values (e.g., need to get the list of RGB strings for a given combination of palette name and colors in the order in which they exist in the data set). Wondering if anyone else had any thoughts on this?
selectindex(v) returns
1. a row vector of column indices j for which v[j]!=0 (v a row vector) or
2. a column vector of row indices i for which v[i]!=0 (v a column vector)
...
selectindex(v)
v: r1 x 1 or 1 x c1
result: r2 x 1 or 1 x c2, r2 <= r1, c2 <= c1
1. a row vector of column indices j for which v[j]!=0 (v a row vector) or
2. a column vector of row indices i for which v[i]!=0 (v a column vector)
...
selectindex(v)
v: r1 x 1 or 1 x c1
result: r2 x 1 or 1 x c2, r2 <= r1, c2 <= c1
Code:
// Loads the data set with palettes used by -brewscheme- use `"`c(sysdir_personal)'b/brewmeta.dta"', clear // Starts mata mata: // Gets the string data from the data set : paletteData = st_sdata(., ("palette", "rgb", "achromatopsia", "protanopia", "deuteranopia", "tritanopia")) // Gets numeric data from the data set : colorData = st_data(., ("colorid", "pcolor", "maxcolors")) // Color palette to use for example functions below : paletteName = "set1" // Gets the indices for the color palette of interest : paletteIDs = selectindex(paletteData[., 1] :== paletteName) // List the matrix indices for this palette : paletteIDs 1 +--------+ 1 | 1062 | 2 | 1063 | 3 | 1064 | 4 | 1065 | 5 | 1066 | 6 | 1067 | 7 | 1068 | 8 | 1069 | 9 | 1070 | 10 | 1071 | 11 | 1072 | 12 | 1073 | 13 | 1074 | 14 | 1075 | 15 | 1076 | 16 | 1077 | 17 | 1078 | 18 | 1079 | 19 | 1080 | 20 | 1081 | 21 | 1082 | 22 | 1083 | 23 | 1084 | 24 | 1085 | 25 | 1086 | 26 | 1087 | 27 | 1088 | 28 | 1089 | 29 | 1090 | 30 | 1091 | 31 | 1092 | 32 | 1093 | 33 | 1094 | +--------+ // Gets all the unique combinations of the number of colors : ncolors = uniqrows(colorData[paletteIDs, 2]) // Displays all of the values that have valid numbers of colors for the given palette : ncolors 1 +-----+ 1 | 3 | 2 | 4 | 3 | 5 | 4 | 6 | 5 | 7 | 6 | 8 | +-----+ // Tests if the number of requested colors is in the unique values : colorIDs = selectindex(ncolors :== 6) : colorIDs 4 : colorIDs = selectindex(ncolors :== 12) : colorIDs :
Comment