How To Rename Columns In R - DBACLASS

Below are the different methods for renaming columns in R-studio tool. Each method uses different libraries. You can follow any one method as per convenience..

DEMO:

Below are the old and new column details:

 

METHOD -1:( using Library : dplyr )

  • To rename single column:
--- Syntax DF %>% Rename ("New name" = "Old Name") --- Example: DF %>% Rename ("Column_1" = "Column_One")
  • To rename Multiple column:
--- Syntax DF %>% Rename ("New name1" = "Old Name1","New name2" = "Old Name2","New name1" = "Old Name1") --- Example: DF %>% Rename ("Column_1" = "Column_One", "Column_2" = "Column_Two", "Column_3" = "Column_Three")

Method -2 ( Using Library : data.table )

  • To rename singel column:
--- Syntax DF=setname(x=df,old=("Old Name"),New=c("New Name")) --- Example: DF=setname(x=df,old=("Column_One"),New=c("Column_1"))
  • To rename Multiple column:
--- Syntax DF=setname(x=df,old=("Old Name1","Old Name2", "Old Name3"),New=c("New Name1","New Name2", "New Name3")) --- Example: DF=setname(x=df,old=("Column_One","Column_Two", "Column_Three"),New=c("Column_1","Column_2", "Column_3"))    

About Admin

View all posts by Admin

Related Articles

  • How to keep or delete columns/Variable of a data frame in R
  • How to change the case (Lower to Upper and Vice Versa) in R
  • How to Read CSV files in R studio

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Comment *

Name *

Email *

Website

Save my name, email, and website in this browser for the next time I comment.

This site uses Akismet to reduce spam. Learn how your comment data is processed. GoogleCustom Search

  • 5ansible
  • 48BACKUP & RECOVERY
  • 6BLOG
  • 16CLOUD
  • 59DATABASE
  • 40DATABASE SCRIPTS
  • 10Database-Wiki
  • 28DATAGUARD
  • 9DB TOOLS
  • 18GOLDENGATE
  • 3HADOOP
  • 47HOW TO
  • 11INTERVIEW QA
  • 61ORACLE 12C
  • 5ORACLE 18C
  • 12ORACLE 19C
  • 59ORACLE RAC
  • 13ORACLE SECURITY
  • 30PERFORMANCE TUNING
  • 29POSTGRES
  • 4R-STUDIO
  • 13SHELL SCRIPT
  • 152TROUBLESHOOTING
  • 3WEBLOGIC
  • Upgrade database from 11g to 12c manually 114105 16
  • Upgrade database from 12.1.0.2 to 12.2.0.1 86301 9
  • ORA-04036: PGA memory used by the instance exceeds PGA_AGGREGATE_LIMIT 85316 3
  • Prerequisite check “CheckActiveFilesAndExecutables” failed 74313 3
  • install oracle goldengate 12c on linux 7 67875 0
  • How to run SQL tuning advisor for a sql_id 65984 9
  • Transparent Data Encryption (TDE) in oracle 12c 55896 2
  • How to drop and recreate temp tablespace in oracle 55830 8
  • ORA-01624: log 1 needed for crash recovery of instance 55220 2
  • Restoring archivelogs from RMAN tape backup 51885 0

Tags

12c 19C archive archivelog ASM Audit AWR backup cloning cloud cluster database dataguard dgmgrl DISKGROUP EDB EXPDP failover flashback goldengate grid impdp multitenant OPATCH ORA- oracle oracle 12.2. oracle 12c partition patch patching PDB pluggable postgres RAC replication rman SCRIPT security SHELL script standby tablespace temp undo upgrade

Tag » How To Rename Columns In R