Using columns with special characters in formulae in R

前端 未结 3 918
一向
一向 2021-01-18 02:06

I\'m trying to make a decision tree using rpart using a data frame that has ~200 columns. Some of these columns have numbers in their names, some have special characters (e.

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-18 02:53

    This works:

    dat <- data.frame(M=rnorm(10),'A/B'=1:10,check.names=F)
    
    > lm(M~`A/B`,dat)
    
    Call:
    lm(formula = M ~ `A/B`, data = dat)
    
    Coefficients:
    (Intercept)        `A/B`  
        -1.0494       0.1214  
    

提交回复
热议问题