0

I have dataframe that contains space in the column name

df <- data.frame("a 1"=c("jan","jan" , "feb"),"t t" =c(10,10,1))
colnames(df) <- c("a 1","t t")

I want to sum the "t t" column on the basis of "a 1" I tried this

df %>% group_by("a 1") %>% summarise(tx = sum("t t"))

the expected result is a dataframe having

  a 1    t t
  jan     20
  feb     1
Sotos
  • 51,121
  • 6
  • 32
  • 66
vishal
  • 855
  • 1
  • 8
  • 16
  • 2
    Use backticks : `df %>% group_by(\`a 1\`) %>% summarise(tx = sum(\`t t\`))` – Ronak Shah Jun 29 '20 at 11:59
  • 2
    Don't use quotes when piping, use backticks (because you have space in your names). i.e. ```df %>% group_by(`a 1`) %>% summarise(tx = sum(`t t`))``` – Sotos Jun 29 '20 at 12:00

1 Answers1

1

Does this work?

df %>% group_by(`a 1`) %>% summarise(tx = sum(`t t`))
Georgery
  • 7,643
  • 1
  • 19
  • 52