[英]In R, how to replace the space in column names with underscore for all columns?
[英]how to pass column names including space in R
假設我的列名是:用戶 ID 和名稱
我應該如何將此列名傳遞給下面的函數?
df %>%
group_by(User ID) %>%
count(name)
顯然,group_by() 或類似函數不接受名稱中帶有空格的列名。
您需要使用tibble
而不是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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.