refer to levels of variablesDear Community
How do I perform a count of the levels of a variable?
In R i can type length(levels(x)).
example: the species of bacteria are levels of the variable "species"
best,
Data TableRe: refer to levels of variablesIf you want unique values in a list or table column here are some functions that will help. The first one is for a list:
/*
Function Name: get_unique_values
Description: Find the unique values in a list. Uses an associative array
Arguments:
in_list List to get unique values for
*/
Get_unique_values = Function( {in_list},
{Default Local},
tmp = [=> 0];
Insert Into( tmp, in_list );
tmp << get keys;
);
For a table column:
/* Function Name Get_Unique_Values_col
Description: Get the unique values for a column. For example:
Indications
------------
AAAAA
BBBBB
AAAAA
CCCCC
CCCCC
unique_list = get_unique_values_col (:Indications)
will return {"AAAAA", "BBBBB", "CCCCC"}
Arguments:
dtcol column descriptor to calculate unique values for
*/
Get_Unique_Values_col = Function( {dtcol},{default local},
// Eval/expr trickery to get this to work.
eval(eval expr(
Summarize(unique_list = By(expr(dtcol)))));
unique_list;
);Re: refer to levels of variablesIf you prefer an interactive solution, use Tables > Summary. Put the column you want as a Group variable and click OK. The number of rows in the resulting data table is the number of levels.
OR
Make the variable you want an ordinal or nominal variable. Use Analyze > Distribution.
Re: refer to levels of variablesHi thanks for this interesting answer. I could not get it to work though. it is undoubtedly due to my lack of skills.