1# Rename column by name: change "beta" to "two"
2names(d)[names(d)=="beta"] <- "two"
3d
4#> alpha two gamma
5#> 1 1 4 7
6#> 2 2 5 8
7#> 3 3 6 9
8
9# You can also rename by position, but this is a bit dangerous if your data
10# can change in the future. If there is a change in the number or positions of
11# columns, then this can result in wrong data.
12
13# Rename by index in names vector: change third item, "gamma", to "three"
14names(d)[3] <- "three"
15d
16#> alpha two three
17#> 1 1 4 7
18#> 2 2 5 8
19#> 3 3 6 9
201# df = dataframe
2# old.var.name = The name you don't like anymore
3# new.var.name = The name you want to get
4
5names(df)[names(df) == 'old.var.name'] <- 'new.var.name'1library(plyr)
2rename(d, c("beta"="two", "gamma"="three"))
3#> alpha two three
4#> 1 1 4 7
5#> 2 2 5 8
6#> 3 3 6 9
71my_data %>%
2 rename(
3 sepal_length = Sepal.Length,
4 sepal_width = Sepal.Width
5 )1df <- rename(df, new_name = old_name) #For renaming dataframe column
2
3tbl <- rename(tbl, new_name = old_name) #For renaming tibble column
4
5tbl <- tbl %>% rename(new_name = old_name) #For renaming tibble column using dplyrpipe
6 #operator
7