Я создаю функцию, которая требует от меня переименования столбцов во фрейме данных, где исходные имена столбцов хранятся в переменной из пользовательского ввода.
#self<span class="math-container">$options$</span>DV is a string identifying the column of interest, such as 'chosenvarname':
DVlabel <- self<span class="math-container">$options$</span>DV
Однако функция dplyr :: rename не работает при использовании этой переменной или ее символа c link:
df1 <-plyr::rename(df1,c(DVlabel='DV'))
df1 <-plyr::rename(df1,c(self<span class="math-container">$options$</span>DV='DV'))
Даже если DVlabel установлен равным допустимое имя столбца во фрейме данных, оно все еще не работает
Оно работает правильно только при использовании фактического имени столбца, что заставляет меня думать, что эта функция не работает с символическими c ссылками:
df1 <-plyr::rename(df1,c(OriginalColumnName='DV'))
Is there another way to use the column name identified in self<span class="math-container">$options$</span>DV as the basis for renaming that same column to something else?
Put differently, is there any way to rename a column using symbolic links to the column name that don't otherwise exist in the data?
Alternatively, is there some way to construct a column reference, such as data<span class="math-container">$var1, where the "var1" component is extracted from some other variable (e.g., DVlabel or self$</span>options$DV?)