Skip to main content

列名の変更

準備

1. パッケージのインストール

install.packages("tidyverse")

2. パッケージの読み込み

library(tidyverse)

プログラム

RPythonSQL
1. 列名を変更AwesomeAwesomeAwesome

1. 列名を変更

構文
df %>%
rename(
new_col1 = col1,
new_col2 = col2
)
サンプルコード
penguins %>%
rename(
BILL_LENGTH_MM = bill_length_mm,
BILL_DEPTH_MM = bill_depth_mm
)

# # A tibble: 344 × 7
# species island BILL_LENGTH_MM BILL_DEPTH_MM flipper_length_mm body_mass_g sex
# <fct> <fct> <dbl> <dbl> <int> <int> <fct>
# 1 Adelie Torgersen 39.1 18.7 181 3750 male
# 2 Adelie Torgersen 39.5 17.4 186 3800 female
# 3 Adelie Torgersen 40.3 18 195 3250 female
# 4 Adelie Torgersen NA NA NA NA NA
# 5 Adelie Torgersen 36.7 19.3 193 3450 female
# 6 Adelie Torgersen 39.3 20.6 190 3650 male
# 7 Adelie Torgersen 38.9 17.8 181 3625 female
# 8 Adelie Torgersen 39.2 19.6 195 4675 male
# 9 Adelie Torgersen 34.1 18.1 193 3475 NA
# 10 Adelie Torgersen 42 20.2 190 4250 NA
# # ℹ 334 more rows
# # ℹ Use `print(n = ...)` to see more rows