column name with brackets or other punctuations for dplyr group_by

前端 未结 2 1222
野趣味
野趣味 2020-12-19 10:43

I have an imported data frame that has column names with various punctuations including parentheses, e.g. BILLNG.STATUS.(COMPLETED./.INCOMPLTE) .

I was

2条回答
  •  再見小時候
    2020-12-19 11:15

    I'm just using this not-an-answer as a counter-example or illustration of limitations for the the backtick method. (It was the first strategem I tried. Perhaps it is the fact that two language operations ("(" and "/") are being handled adjacently that makes this fail.)

    names(iris)[5] <- "Specie(/)s"
    library(dplyr)
    by_species <- iris %>% group_by(`Specie(/)s`)
    by_species %>% summarise_each(funs(mean(., na.rm = TRUE)))
    #Error: cannot modify grouping variable
    

    Tried a variety or other language-oriented efforts with quote, as.name and substitute that also failed. (I wish there were a mechanism to request that this sink to the bottom of the answers.)

提交回复
热议问题