Getting strings recognized as variable names in R

后端 未结 6 1797
我在风中等你
我在风中等你 2020-11-28 18:39

Related: Strings as variable references in R
Possibly related: Concatenate expressions to subset a dataframe


I\'ve simplified the question per the comment

6条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-28 19:03

    What works best for me is using quote() and eval() together.

    For example, let's print each column using a for loop:

    Columns <- names(dat)
    for (i in 1:ncol(dat)){
      dat[, eval(quote(Columns[i]))] %>% print
    }
    

提交回复
热议问题