I appreciate your assistance with either suggesting a package or a base R solution to the following problem (Thank you in advance.)
Imagine I have a vector of character elements from a statistical_function (below). If I provide the name of two character elements (e.g., provided = c("high", "aware")), then I want a mechanism to produce the following binary vector for me: desired_vector = c(0,1,1,0,1).
Length: This desired_vector has the same length as the number of elements in the output of the statistical function MINUS the element named intrcpt. Thus, in this case, desired_vector will have 5 elements.
Elements A: For each element in the statistical_function's output that doesn't contain : (e.g., "weekhigh") but does contain one of the provided vector's elements ("high") my desired vector should be 1.
Elements B: For each element in the statistical function's output that does contain : (e.g., "weekhigh:testeraware") and does contain BOTH of the provided vector's elements ("high" & "aware") my desired vector should be 1.
Else all remaining elements in the desired_vector should be 0. Is this possible to achieve in R?
In the below example, 1st element of desired_vector is 0 because intrcpt aside, weekssome doesn't contain either "high" or "aware", 2nd element is 1 because weekshigh has "high", 3rd element is 1 because "testeraware" contains "aware", 4th element is 0 because "weekssome:testeraware" doesn't contain BOTH "high" and "aware", and 5th element is 1 because it does contain BOTH "high" and "aware".
statistical_function = c("intrcpt","weekssome","weekshigh",
"testeraware","weekssome:testeraware","weekshigh:testeraware")
# [1] "intrcpt" "weekssome" "weekshigh"
# [4] "testeraware" "weekssome:testeraware" "weekshigh:testeraware"
provided_vector = c("high", "aware")
desired_vector = c(0, 1, 1, 0, 1)