@rename
Renaming colummns follows the same syntax as in R's tidyverse
, where the "tidy expression" is new_name = old_name
. While the main function to rename columns is @rename()
, you can also use @select()
if you additionally plan to select only the renamed columns.
using Tidier
using RDatasets
movies = dataset("ggplot2", "movies");
Rename using @rename()
¤
If you only want to rename the columns without selecting them, then this is where @rename()
comes in handy. For the sake of brevity, we are selecting the first 5 columns and rows after performing the @rename()
.
@chain movies begin
@rename(title = Title, Minutes = Length)
@select(1:5)
@slice(1:5)
end
5×5 DataFrame
Row | title | Year | Minutes | Budget | Rating |
---|---|---|---|---|---|
String | Int32 | Int32 | Int32? | Float64 | |
1 | $ | 1971 | 121 | missing | 6.4 |
2 | $1000 a Touchdown | 1939 | 71 | missing | 6.0 |
3 | $21 a Day Once a Month | 1941 | 7 | missing | 8.2 |
4 | $40,000 | 1996 | 70 | missing | 8.2 |
5 | $50,000 Climax Show, The | 1975 | 71 | missing | 3.4 |
Rename using @select()
¤
If you plan to only select those columns that you would like to rename, then you can use @select()
to both rename and select the columns of interest.
@chain movies begin
@select(title = Title, Minutes = Length)
@slice(1:5)
end
5×2 DataFrame
Row | title | Minutes |
---|---|---|
String | Int32 | |
1 | $ | 121 |
2 | $1000 a Touchdown | 71 |
3 | $21 a Day Once a Month | 7 |
4 | $40,000 | 70 |
5 | $50,000 Climax Show, The | 71 |
This page was generated using Literate.jl.