Creating formula using very long strings in R

前端 未结 3 814
挽巷
挽巷 2021-01-19 14:43

I\'m in a situation where I have a vector full of column names for a really large data frame.

Let\'s assume: x = c(\"Name\", \"address\", \"Gender\", ......, \

3条回答
  •  -上瘾入骨i
    2021-01-19 15:37

    You may try reformulate

     reformulate(setdiff(x, 'class'), response='class')
     #class ~ Name + address + Gender
    

    where 'x' is

      x <- c("Name", "address", "Gender", 'class')
    

    If R keywords are in the 'x', you can do

       reformulate('.', response='class')
       #class ~ .
    

提交回复
热议问题