Skip to content

Commit

Permalink
first rename_col first function Mook
Browse files Browse the repository at this point in the history
  • Loading branch information
nmouquet authored and ahasverus committed May 2, 2023
1 parent f8f4ac2 commit 4e8eac4
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 0 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ export(get_world_basemap)
export(leading_zero)
export(len)
export(multi_merge)
export(rename_col)
export(to_binomial_name)
19 changes: 19 additions & 0 deletions R/rename_col.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#' Rename any columns of a dataframe (from 1 to as much columns as you want)
#'
#' @param df a dataframe.
#' @param old.col.names a vector of columns names to rename
#' @param new.col.names a vector of columns new names
#'
#' @return a dataframe.
#'
#' @export
#'
#' @examples
#' df <- cbind.data.frame(a=1:10,b=1:10,c=1:10,d=1:10)
#' df <- rename_col(df,old.col.names=c("a","d"),new.col.names=c("aa","dd"))
#'

rename_col <- function(df, old.col.names, new.col.names){
for (i in 1:length(old.col.names)) names(df)[names(df) == old.col.names[i]] <- new.col.names[i]
df
}
2 changes: 2 additions & 0 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ library("rutils")

- [`address_to_coords()`](https://frbcesab.github.io/rutils/reference/address_to_coords.html): gets geographic coordinates of any location in the World

- [`rename_col()`](https://frbcesab.github.io/rutils/reference/rename_col.html): Rename any columns of a dataframe (from 1 to as much columns as you want)


## Contribution

Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ library("rutils")
- [`address_to_coords()`](https://frbcesab.github.io/rutils/reference/address_to_coords.html):
gets geographic coordinates of any location in the World

- [`rename_col()`](https://frbcesab.github.io/rutils/reference/rename_col.html):
Rename any columns of a dataframe (from 1 to as much columns as you
want)

## Contribution

Visit the
Expand Down
26 changes: 26 additions & 0 deletions man/rename_col.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4e8eac4

Please sign in to comment.