dplyr select 列,当列名是数字时

dplyr select column when column name is number

我想重塑数据,然后 select 特定列。

data(ChickWeight)
chick <- ChickWeight %>% spread(Time,weight) %>% filter(Diet=="1")

它为我创建了列名,它们是数字。那么我怎么能 select 名为“0”的列呢?我知道 %>% select(3) 可能有效,但我需要 select 列名称为数字的解决方案。

对名称为数字

的select列使用反引号
data(ChickWeight)
library(dplyr)
library(tidyr)
chick <- ChickWeight %>% spread(Time,weight) %>% filter(Diet==2) %>% select(`0`)