Reputation: 841
Suppose I have a dataset, CT_Data, in list format with internet1_group as an item in the list such that:
$ internet1_group : Factor w/ 3 levels "1","2","3": 3 1 2 1 1 3 2 1 2 1 ...
I will be creating Dependent_Variable_List as a character with the following value:
Dependent_Variable_List <- Dependent_Variable_List[Dependent_Variable_List %in% colnames(CT_Data)]
Dependent_Variable_List
[1] "internet1_group"
Now I'm trying to index Dependent_Variable levels in dataset CT_Data, and store the levels in CT_Vars list.
CT_Vars <- list()
CT_Vars[["DV_Levels"]] <- levels(CT_Data[, Dependent_Variable_List])
I keep on getting CT_Vars[["DV_Levels"]]
as NULL
, could anyone help me to debug the issue? Thanks!
Upvotes: 1
Views: 372
Reputation: 740
You're saying that CT_Data is a list, but your call is structured for a data frame. Does this work? If not, can you run dput(CT_Data)
and paste the results in your question?
CT_Vars[["DV_Levels"]] <- levels(CT_Data[[Dependent_Variable_List]])
Upvotes: 2