<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	
	>
<channel>
	<title>
	Comments on: Rename Data Frame Columns in R	</title>
	<atom:link href="https://www.datanovia.com/en/lessons/rename-data-frame-columns-in-r/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.datanovia.com/en/lessons/rename-data-frame-columns-in-r/</link>
	<description>Data Mining and Statistics for Decision Support</description>
	<lastBuildDate>Sun, 23 Mar 2025 21:31:02 +0000</lastBuildDate>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.2</generator>
	<item>
		<title>
		By: Wilson		</title>
		<link>https://www.datanovia.com/en/lessons/rename-data-frame-columns-in-r/#comment-29348</link>

		<dc:creator><![CDATA[Wilson]]></dc:creator>
		<pubDate>Sun, 23 Mar 2025 21:31:02 +0000</pubDate>
		<guid isPermaLink="false">https://www.datanovia.com/en/?post_type=dt_lessons&#038;p=7237#comment-29348</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.datanovia.com/en/lessons/rename-data-frame-columns-in-r/#comment-2047&quot;&gt;kassambara&lt;/a&gt;.

Thank you so much this is the only thing that has worked for me]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.datanovia.com/en/lessons/rename-data-frame-columns-in-r/#comment-2047">kassambara</a>.</p>
<p>Thank you so much this is the only thing that has worked for me</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: venkatapanchumarthi		</title>
		<link>https://www.datanovia.com/en/lessons/rename-data-frame-columns-in-r/#comment-29068</link>

		<dc:creator><![CDATA[venkatapanchumarthi]]></dc:creator>
		<pubDate>Tue, 20 Feb 2024 07:04:27 +0000</pubDate>
		<guid isPermaLink="false">https://www.datanovia.com/en/?post_type=dt_lessons&#038;p=7237#comment-29068</guid>

					<description><![CDATA[Hi i am Venkatapanchumarthi.
Awesome. I read excellent artcicle in recent days, this post is very informative this article is helped me a lot .Thanks for sharing such useful information.]]></description>
			<content:encoded><![CDATA[<p>Hi i am Venkatapanchumarthi.<br />
Awesome. I read excellent artcicle in recent days, this post is very informative this article is helped me a lot .Thanks for sharing such useful information.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Sala Lotfi		</title>
		<link>https://www.datanovia.com/en/lessons/rename-data-frame-columns-in-r/#comment-19760</link>

		<dc:creator><![CDATA[Sala Lotfi]]></dc:creator>
		<pubDate>Sat, 02 May 2020 01:24:55 +0000</pubDate>
		<guid isPermaLink="false">https://www.datanovia.com/en/?post_type=dt_lessons&#038;p=7237#comment-19760</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.datanovia.com/en/lessons/rename-data-frame-columns-in-r/#comment-1984&quot;&gt;Norman Munyengwa&lt;/a&gt;.

This might help you...Kan has nicely described this..
https://blog.exploratory.io/selecting-columns-809bdd1ef615

df %&#062;% 
  select(-starts_with(&quot;user.&quot;), -starts_with(&quot;milestone.&quot;), 
         -starts_with(&quot;pull_&quot;), -ends_with(&quot;url&quot;)) %&#062;% 
  rename(developer = assignee.login) %&#062;%
  select(-starts_with(&quot;assignee&quot;), -title, -comments, -locked, -labels, -id, -body)]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.datanovia.com/en/lessons/rename-data-frame-columns-in-r/#comment-1984">Norman Munyengwa</a>.</p>
<p>This might help you&#8230;Kan has nicely described this..<br />
<a href="https://blog.exploratory.io/selecting-columns-809bdd1ef615" rel="nofollow ugc">https://blog.exploratory.io/selecting-columns-809bdd1ef615</a></p>
<p>df %&gt;%<br />
  select(-starts_with(&#8220;user.&#8221;), -starts_with(&#8220;milestone.&#8221;),<br />
         -starts_with(&#8220;pull_&#8221;), -ends_with(&#8220;url&#8221;)) %&gt;%<br />
  rename(developer = assignee.login) %&gt;%<br />
  select(-starts_with(&#8220;assignee&#8221;), -title, -comments, -locked, -labels, -id, -body)</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Abdoulaye Sarr		</title>
		<link>https://www.datanovia.com/en/lessons/rename-data-frame-columns-in-r/#comment-3712</link>

		<dc:creator><![CDATA[Abdoulaye Sarr]]></dc:creator>
		<pubDate>Mon, 16 Dec 2019 16:44:02 +0000</pubDate>
		<guid isPermaLink="false">https://www.datanovia.com/en/?post_type=dt_lessons&#038;p=7237#comment-3712</guid>

					<description><![CDATA[I have a matrix with column data as years as date but when using as.Date it expects something %y%m%d how to rename column to %Y only as date but not character?
example 2001-01-01 rename as 2001]]></description>
			<content:encoded><![CDATA[<p>I have a matrix with column data as years as date but when using as.Date it expects something %y%m%d how to rename column to %Y only as date but not character?<br />
example 2001-01-01 rename as 2001</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Moses		</title>
		<link>https://www.datanovia.com/en/lessons/rename-data-frame-columns-in-r/#comment-2235</link>

		<dc:creator><![CDATA[Moses]]></dc:creator>
		<pubDate>Wed, 28 Aug 2019 11:30:45 +0000</pubDate>
		<guid isPermaLink="false">https://www.datanovia.com/en/?post_type=dt_lessons&#038;p=7237#comment-2235</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.datanovia.com/en/lessons/rename-data-frame-columns-in-r/#comment-2185&quot;&gt;kassambara&lt;/a&gt;.

You are goooood!]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.datanovia.com/en/lessons/rename-data-frame-columns-in-r/#comment-2185">kassambara</a>.</p>
<p>You are goooood!</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Thomas		</title>
		<link>https://www.datanovia.com/en/lessons/rename-data-frame-columns-in-r/#comment-2186</link>

		<dc:creator><![CDATA[Thomas]]></dc:creator>
		<pubDate>Thu, 08 Aug 2019 07:41:13 +0000</pubDate>
		<guid isPermaLink="false">https://www.datanovia.com/en/?post_type=dt_lessons&#038;p=7237#comment-2186</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.datanovia.com/en/lessons/rename-data-frame-columns-in-r/#comment-2185&quot;&gt;kassambara&lt;/a&gt;.

Kassambara - you are a hero. Thanks a million for your extremely detailed answer. I was hoping for some hints and get a full code - much appreciated.
/T]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.datanovia.com/en/lessons/rename-data-frame-columns-in-r/#comment-2185">kassambara</a>.</p>
<p>Kassambara &#8211; you are a hero. Thanks a million for your extremely detailed answer. I was hoping for some hints and get a full code &#8211; much appreciated.<br />
/T</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: kassambara		</title>
		<link>https://www.datanovia.com/en/lessons/rename-data-frame-columns-in-r/#comment-2185</link>

		<dc:creator><![CDATA[kassambara]]></dc:creator>
		<pubDate>Thu, 08 Aug 2019 07:15:07 +0000</pubDate>
		<guid isPermaLink="false">https://www.datanovia.com/en/?post_type=dt_lessons&#038;p=7237#comment-2185</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.datanovia.com/en/lessons/rename-data-frame-columns-in-r/#comment-2181&quot;&gt;Thomas&lt;/a&gt;.

Hi Thomas,

you need to perform some string manipulations as shown below.

&lt;pre class = &quot;r_code&quot;&gt;
library(tidyverse)
library(stringr) 

# Demo data peparation
iris &lt;- as_tibble(iris)
colnames(iris) &lt;- c(&quot;alt1.price&quot;, &quot;alt2.price&quot;, &quot;alt2.pol&quot;, &quot;alt2.x&quot;, &quot;y&quot;)
iris

# Helper function to rename columns containing alt
rename_column &lt;- function(x){
  library(stringr)
  alt &lt;- x %&gt;% str_extract(&quot;^alt[0-9]+\\.&quot;)
  if(is.na(alt)){
    # stop here and return x, because it doesn&#039;t start with &quot;alt&quot;
    return(x)
  }
  suffix &lt;- x %&gt;% str_replace(pattern = alt, replacement = &quot;&quot;)
  number &lt;- alt %&gt;% str_replace_all(pattern = &quot;alt&#124;\\.&quot;, &quot;&quot;)
  new.name &lt;- paste(suffix, number, sep = &quot;_&quot;)
  return(new.name)
}

# Renaming columns
columns &lt;- colnames(iris)
colnames(iris) &lt;- columns %&gt;% map(rename_column)
iris
&lt;/pre&gt;]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.datanovia.com/en/lessons/rename-data-frame-columns-in-r/#comment-2181">Thomas</a>.</p>
<p>Hi Thomas,</p>
<p>you need to perform some string manipulations as shown below.</p>
<pre class = "r_code">
library(tidyverse)
library(stringr) 

# Demo data peparation
iris <- as_tibble(iris)
colnames(iris) <- c("alt1.price", "alt2.price", "alt2.pol", "alt2.x", "y")
iris

# Helper function to rename columns containing alt
rename_column <- function(x){
  library(stringr)
  alt <- x %>% str_extract("^alt[0-9]+\\.")
  if(is.na(alt)){
    # stop here and return x, because it doesn't start with "alt"
    return(x)
  }
  suffix <- x %>% str_replace(pattern = alt, replacement = "")
  number <- alt %>% str_replace_all(pattern = "alt|\\.", "")
  new.name <- paste(suffix, number, sep = "_")
  return(new.name)
}

# Renaming columns
columns <- colnames(iris)
colnames(iris) <- columns %>% map(rename_column)
iris
</pre>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Thomas		</title>
		<link>https://www.datanovia.com/en/lessons/rename-data-frame-columns-in-r/#comment-2181</link>

		<dc:creator><![CDATA[Thomas]]></dc:creator>
		<pubDate>Wed, 07 Aug 2019 12:27:16 +0000</pubDate>
		<guid isPermaLink="false">https://www.datanovia.com/en/?post_type=dt_lessons&#038;p=7237#comment-2181</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.datanovia.com/en/lessons/rename-data-frame-columns-in-r/#comment-2011&quot;&gt;kassambara&lt;/a&gt;.

Hi Kassambara,

You seem to be really on top of how to rename columns and I&#039;m been struggling with writing a code that can rename columns based on their names.  I have many different dataset where a number of columns will start with &quot;alt&quot; (e.g. alt1.price, alt1.pol, alt1.x, alt2.price, alt2.pol, alt2.x) and I would like to rename these columns to price_1, pol_1, x_1, price_2, pol_2, x_3.

Essentially, I would like to select columns starting with alt, add an underscore, delete the &#039;alt&#039; and move the number to the end of the column name. Is that possible in any way? 

Kind regards, Thomas]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.datanovia.com/en/lessons/rename-data-frame-columns-in-r/#comment-2011">kassambara</a>.</p>
<p>Hi Kassambara,</p>
<p>You seem to be really on top of how to rename columns and I&#8217;m been struggling with writing a code that can rename columns based on their names.  I have many different dataset where a number of columns will start with &#8220;alt&#8221; (e.g. alt1.price, alt1.pol, alt1.x, alt2.price, alt2.pol, alt2.x) and I would like to rename these columns to price_1, pol_1, x_1, price_2, pol_2, x_3.</p>
<p>Essentially, I would like to select columns starting with alt, add an underscore, delete the &#8216;alt&#8217; and move the number to the end of the column name. Is that possible in any way? </p>
<p>Kind regards, Thomas</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Felix Kennith Chan		</title>
		<link>https://www.datanovia.com/en/lessons/rename-data-frame-columns-in-r/#comment-2048</link>

		<dc:creator><![CDATA[Felix Kennith Chan]]></dc:creator>
		<pubDate>Sun, 16 Jun 2019 01:41:31 +0000</pubDate>
		<guid isPermaLink="false">https://www.datanovia.com/en/?post_type=dt_lessons&#038;p=7237#comment-2048</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.datanovia.com/en/lessons/rename-data-frame-columns-in-r/#comment-2047&quot;&gt;kassambara&lt;/a&gt;.

Is there a way where I don&#039;t do c(&quot;newname1&quot;, &quot;newname2&quot;, &quot;newname3&quot;, ... , &quot;newname200&quot;)?]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.datanovia.com/en/lessons/rename-data-frame-columns-in-r/#comment-2047">kassambara</a>.</p>
<p>Is there a way where I don&#8217;t do c(&#8220;newname1&#8221;, &#8220;newname2&#8221;, &#8220;newname3&#8221;, &#8230; , &#8220;newname200&#8221;)?</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: kassambara		</title>
		<link>https://www.datanovia.com/en/lessons/rename-data-frame-columns-in-r/#comment-2047</link>

		<dc:creator><![CDATA[kassambara]]></dc:creator>
		<pubDate>Sat, 15 Jun 2019 10:28:37 +0000</pubDate>
		<guid isPermaLink="false">https://www.datanovia.com/en/?post_type=dt_lessons&#038;p=7237#comment-2047</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.datanovia.com/en/lessons/rename-data-frame-columns-in-r/#comment-2046&quot;&gt;Felix Kennith Chan&lt;/a&gt;.

You can also go as follow:

&lt;pre class = &quot;r_code&quot;&gt;
colnames(my_data) = c(&quot;newname1&quot;, &quot;newname2&quot;, &quot;newname3&quot;)
&lt;/pre&gt;]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.datanovia.com/en/lessons/rename-data-frame-columns-in-r/#comment-2046">Felix Kennith Chan</a>.</p>
<p>You can also go as follow:</p>
<pre class = "r_code">
colnames(my_data) = c("newname1", "newname2", "newname3")
</pre>
]]></content:encoded>
		
			</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/

Object Caching 109/188 objects using Memcached
Page Caching using Disk: Enhanced 
Lazy Loading (feed)
Database Caching 36/58 queries in 0.117 seconds using APC

Served from: www.datanovia.com @ 2025-07-29 10:17:11 by W3 Total Cache
-->