Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to pass column names including space in R

assume my column names are: User ID and name
how should I pass this column name to functions like what I have below?

df %>%
  group_by(User ID) %>%
  count(name)

apparently, group_by() or similar functions do not accept column names with space in their names.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You need to use tibble instead of data.frame:

library(tidyverse)

df <- tibble(`User ID` = 1:2, x = 5:6)
  
df %>%
  group_by(`User ID`) %>% 
  summarise(total = sum(x))

#> # A tibble: 2 × 2
#>   `User ID` total
#>       <int> <int>
#> 1         1     5
#> 2         2     6
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading