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.

0

1 Answer 1

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`)
1
  • 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. Commented Feb 2, 2017 at 16:11

Not the answer you're looking for? Browse other questions tagged or ask your own question.