2

I want to reshape the data and then select a specific column.

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

It creates the column names for me, which are numbers. So how could I select the column that named "0"? I know that %>% select(3) may work, but I need the solution to select columns with their names being number.

Zero
  • 23
  • 1
  • 4

1 Answers1

5

Use backticks to select columns with their names being number

data(ChickWeight)
library(dplyr)
library(tidyr)
chick <- ChickWeight %>% spread(Time,weight) %>% filter(Diet==2) %>% select(`0`)
v.grabovets
  • 607
  • 8
  • 8
  • Your answer essentially was correct. It probably was downvoted - I corrected this - because you did not test your answer (there is no `0`), and the recommended way is to make the question/answer self-contained. – Dieter Menne Feb 02 '17 at 16:11