I know that it's possible to embed an ifelse statement within a dplyr mutate call, but in this case I am running a customized regression on customized datasets that are generated based on a combination of parameters specified on different rows of a dataframe. I would like to add to each customized dataset only the variables that are going to be used in that customized regression. In other words, I want to start with a baseline dataset, and then selectively mutate to add new columns only if parameters from the previous column hold certain values.
Say I have a parameter column called "fixed.effects" which can take on values of 1,2, or 3. I want to use mutate to add dummy variables from blocks A, B, or C, corresponding to the value of fixed.effects. In order to add the dummy variable, I use an ifelse statement inside mutate to check the value of other variables within the customized (nested) dataframe. But how can I get my function to check the value of the fixed.effects column, which is outside the nested dataframe (it's one of the variables that was used for group_by), and only perform the mutate that corresponds to a given value of fixed.effects?
in terms of how I plan to execute this, I have a function that has the mutate function inside of it, and I plan to use the purrr:map series to apply this function in a rowwise manner to each of the rows of parameter combinations (including values of fixed.effects). I'm hoping that the value of fixed.effects can serve as an input into this function so that it knows which columns to add.
Thanks in advance, and sorry if this is a silly question...