<?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: Compute and Add new Variables to a Data Frame in R	</title>
	<atom:link href="https://www.datanovia.com/en/lessons/compute-and-add-new-variables-to-a-data-frame-in-r/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.datanovia.com/en/lessons/compute-and-add-new-variables-to-a-data-frame-in-r/</link>
	<description>Data Mining and Statistics for Decision Support</description>
	<lastBuildDate>Wed, 25 Mar 2020 17:09:30 +0000</lastBuildDate>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.2</generator>
	<item>
		<title>
		By: Mels		</title>
		<link>https://www.datanovia.com/en/lessons/compute-and-add-new-variables-to-a-data-frame-in-r/#comment-11164</link>

		<dc:creator><![CDATA[Mels]]></dc:creator>
		<pubDate>Wed, 25 Mar 2020 17:09:30 +0000</pubDate>
		<guid isPermaLink="false">https://www.datanovia.com/en/?post_type=dt_lessons&#038;p=7238#comment-11164</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.datanovia.com/en/lessons/compute-and-add-new-variables-to-a-data-frame-in-r/#comment-1506&quot;&gt;kassambara&lt;/a&gt;.

Hello, 
I am pretty new to R...
I created a new column var (all_bis) using mutate () to add to existing ones to my database (roma_obs) . The new var is the difference between two vars (see code below). I could not use the rename () function as I did not really understand its use (perhaps it is needed in case I want to replace a var rather than adding a new one?). 

I need to save the new column var (all_bis) to either the existing (roma_obs) or a new database (roma_obs_bis) in excel (would be better the first solution). However I have problems with your code lines at this step. I used the write_xls () for excel files...without success (Error in is.data.frame(x) : object &quot;roma_obs_bis&quot; not found). 

Do you have suggestions how to overwrite existing db in Excel with the new one including the new var??


roma_obs_bis %
mutate(all_bis = roma_obs$all - roma_obs$all_0_30) %&#062;%
rename(all = all_bis) # NOT SURE

 write_xlsx(roma_obs_bis, path = tempfile(fileext = &#039;...\roma_obs_bis.xlsx&#039;)) # NOT SURE


Thank you very much for your help]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.datanovia.com/en/lessons/compute-and-add-new-variables-to-a-data-frame-in-r/#comment-1506">kassambara</a>.</p>
<p>Hello,<br />
I am pretty new to R&#8230;<br />
I created a new column var (all_bis) using mutate () to add to existing ones to my database (roma_obs) . The new var is the difference between two vars (see code below). I could not use the rename () function as I did not really understand its use (perhaps it is needed in case I want to replace a var rather than adding a new one?). </p>
<p>I need to save the new column var (all_bis) to either the existing (roma_obs) or a new database (roma_obs_bis) in excel (would be better the first solution). However I have problems with your code lines at this step. I used the write_xls () for excel files&#8230;without success (Error in is.data.frame(x) : object &#8220;roma_obs_bis&#8221; not found). </p>
<p>Do you have suggestions how to overwrite existing db in Excel with the new one including the new var??</p>
<p>roma_obs_bis %<br />
mutate(all_bis = roma_obs$all &#8211; roma_obs$all_0_30) %&gt;%<br />
rename(all = all_bis) # NOT SURE</p>
<p> write_xlsx(roma_obs_bis, path = tempfile(fileext = &#8216;&#8230;\roma_obs_bis.xlsx&#8217;)) # NOT SURE</p>
<p>Thank you very much for your help</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: kassambara		</title>
		<link>https://www.datanovia.com/en/lessons/compute-and-add-new-variables-to-a-data-frame-in-r/#comment-2245</link>

		<dc:creator><![CDATA[kassambara]]></dc:creator>
		<pubDate>Sun, 01 Sep 2019 08:44:23 +0000</pubDate>
		<guid isPermaLink="false">https://www.datanovia.com/en/?post_type=dt_lessons&#038;p=7238#comment-2245</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.datanovia.com/en/lessons/compute-and-add-new-variables-to-a-data-frame-in-r/#comment-2242&quot;&gt;Galo&lt;/a&gt;.

Try the function arrange() [in dplyr package].

Read more at: https://www.datanovia.com/en/lessons/reorder-data-frame-rows-in-r/]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.datanovia.com/en/lessons/compute-and-add-new-variables-to-a-data-frame-in-r/#comment-2242">Galo</a>.</p>
<p>Try the function arrange() [in dplyr package].</p>
<p>Read more at: <a href="https://www.datanovia.com/en/lessons/reorder-data-frame-rows-in-r/" rel="ugc">https://www.datanovia.com/en/lessons/reorder-data-frame-rows-in-r/</a></p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Galo		</title>
		<link>https://www.datanovia.com/en/lessons/compute-and-add-new-variables-to-a-data-frame-in-r/#comment-2242</link>

		<dc:creator><![CDATA[Galo]]></dc:creator>
		<pubDate>Sat, 31 Aug 2019 12:47:17 +0000</pubDate>
		<guid isPermaLink="false">https://www.datanovia.com/en/?post_type=dt_lessons&#038;p=7238#comment-2242</guid>

					<description><![CDATA[Hi , 

How can i sort a column after piping?

For example : 
Code : { aggregate(df[, c(3)], list(Region = df$Region),  mean) %&#062;% 
               left_join(count(df, &quot;Region&quot;)) }

I get : 
                           Region                        x                               freq
1        Australia and New Zealand   7.298000                      2
2       Central and Eastern Europe   5.469448                     29
3                     Eastern Asia                 5.672000                      6
4      Latin America and Caribbean  5.950136                      22
5  Middle East and Northern Africa 5.294158                     19
6                    North America              7.107000                    2
 ... 
&#062; now i want to sort x descending .. i tried : 
{  &quot;%&#062;%
            sort( x, decreasing = TRUE)  }
and get error : Error in do.call(&quot;order&quot;, c(z, list(na.last = na.last, decreasing = decreasing,  : 
  object &#039;x&#039; not found

How can i sort the output of piping ? 

Thnaks !! :]]]></description>
			<content:encoded><![CDATA[<p>Hi , </p>
<p>How can i sort a column after piping?</p>
<p>For example :<br />
Code : { aggregate(df[, c(3)], list(Region = df$Region),  mean) %&gt;%<br />
               left_join(count(df, &#8220;Region&#8221;)) }</p>
<p>I get :<br />
                           Region                        x                               freq<br />
1        Australia and New Zealand   7.298000                      2<br />
2       Central and Eastern Europe   5.469448                     29<br />
3                     Eastern Asia                 5.672000                      6<br />
4      Latin America and Caribbean  5.950136                      22<br />
5  Middle East and Northern Africa 5.294158                     19<br />
6                    North America              7.107000                    2<br />
 &#8230;<br />
&gt; now i want to sort x descending .. i tried :<br />
{  &#8220;%&gt;%<br />
            sort( x, decreasing = TRUE)  }<br />
and get error : Error in do.call(&#8220;order&#8221;, c(z, list(na.last = na.last, decreasing = decreasing,  :<br />
  object &#8216;x&#8217; not found</p>
<p>How can i sort the output of piping ? </p>
<p>Thnaks !! :]</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: kassambara		</title>
		<link>https://www.datanovia.com/en/lessons/compute-and-add-new-variables-to-a-data-frame-in-r/#comment-2126</link>

		<dc:creator><![CDATA[kassambara]]></dc:creator>
		<pubDate>Thu, 18 Jul 2019 21:15:11 +0000</pubDate>
		<guid isPermaLink="false">https://www.datanovia.com/en/?post_type=dt_lessons&#038;p=7238#comment-2126</guid>

					<description><![CDATA[yes it is, fixed now, thanks!!]]></description>
			<content:encoded><![CDATA[<p>yes it is, fixed now, thanks!!</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Ydoo		</title>
		<link>https://www.datanovia.com/en/lessons/compute-and-add-new-variables-to-a-data-frame-in-r/#comment-2119</link>

		<dc:creator><![CDATA[Ydoo]]></dc:creator>
		<pubDate>Thu, 18 Jul 2019 10:38:56 +0000</pubDate>
		<guid isPermaLink="false">https://www.datanovia.com/en/?post_type=dt_lessons&#038;p=7238#comment-2119</guid>

					<description><![CDATA[isn&#039;t  transmute()  rather than transmutate()?]]></description>
			<content:encoded><![CDATA[<p>isn&#8217;t  transmute()  rather than transmutate()?</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: kassambara		</title>
		<link>https://www.datanovia.com/en/lessons/compute-and-add-new-variables-to-a-data-frame-in-r/#comment-1924</link>

		<dc:creator><![CDATA[kassambara]]></dc:creator>
		<pubDate>Tue, 07 May 2019 19:12:52 +0000</pubDate>
		<guid isPermaLink="false">https://www.datanovia.com/en/?post_type=dt_lessons&#038;p=7238#comment-1924</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.datanovia.com/en/lessons/compute-and-add-new-variables-to-a-data-frame-in-r/#comment-1923&quot;&gt;Julia&lt;/a&gt;.

Normally, you just need to load the tidyverse package.

The function `%&gt;%` is available in the magrittr package, which is automatically loaded by tidyverse.

Please, try this:

&lt;pre class = &quot;r_code&quot;&gt;
library(tidyverse)
library(magrittr)
&lt;/pre&gt;]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.datanovia.com/en/lessons/compute-and-add-new-variables-to-a-data-frame-in-r/#comment-1923">Julia</a>.</p>
<p>Normally, you just need to load the tidyverse package.</p>
<p>The function `%>%` is available in the magrittr package, which is automatically loaded by tidyverse.</p>
<p>Please, try this:</p>
<pre class = "r_code">
library(tidyverse)
library(magrittr)
</pre>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Julia		</title>
		<link>https://www.datanovia.com/en/lessons/compute-and-add-new-variables-to-a-data-frame-in-r/#comment-1923</link>

		<dc:creator><![CDATA[Julia]]></dc:creator>
		<pubDate>Mon, 06 May 2019 16:22:18 +0000</pubDate>
		<guid isPermaLink="false">https://www.datanovia.com/en/?post_type=dt_lessons&#038;p=7238#comment-1923</guid>

					<description><![CDATA[Hello, I get the error message &quot;could not find function &quot;%&#062;%&quot;&quot; when I try to run the code. I&#039;ve installed the packages mentioned and I&#039;m rather new to R so I don&#039;t know how to solve the problem. Could anyone help?]]></description>
			<content:encoded><![CDATA[<p>Hello, I get the error message &#8220;could not find function &#8220;%&gt;%&#8221;&#8221; when I try to run the code. I&#8217;ve installed the packages mentioned and I&#8217;m rather new to R so I don&#8217;t know how to solve the problem. Could anyone help?</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: mangogul		</title>
		<link>https://www.datanovia.com/en/lessons/compute-and-add-new-variables-to-a-data-frame-in-r/#comment-1507</link>

		<dc:creator><![CDATA[mangogul]]></dc:creator>
		<pubDate>Sat, 03 Nov 2018 10:12:46 +0000</pubDate>
		<guid isPermaLink="false">https://www.datanovia.com/en/?post_type=dt_lessons&#038;p=7238#comment-1507</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.datanovia.com/en/lessons/compute-and-add-new-variables-to-a-data-frame-in-r/#comment-1506&quot;&gt;kassambara&lt;/a&gt;.

Many thanks!

I realize I was struggling to understand the pipe concept.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.datanovia.com/en/lessons/compute-and-add-new-variables-to-a-data-frame-in-r/#comment-1506">kassambara</a>.</p>
<p>Many thanks!</p>
<p>I realize I was struggling to understand the pipe concept.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: kassambara		</title>
		<link>https://www.datanovia.com/en/lessons/compute-and-add-new-variables-to-a-data-frame-in-r/#comment-1506</link>

		<dc:creator><![CDATA[kassambara]]></dc:creator>
		<pubDate>Sat, 03 Nov 2018 09:05:57 +0000</pubDate>
		<guid isPermaLink="false">https://www.datanovia.com/en/?post_type=dt_lessons&#038;p=7238#comment-1506</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.datanovia.com/en/lessons/compute-and-add-new-variables-to-a-data-frame-in-r/#comment-1505&quot;&gt;mangogul&lt;/a&gt;.

It&#039;s not virtual, you need to create a new R object to hold the modified data frame; then, you can save or manipulate the data again.

For example:

&lt;pre class = &quot;r_code&quot;&gt;
library(tidyverse)
my_modified_data &lt;- iris %&gt;%
  mutate(sep.lw = Sepal.Length*Sepal.Width) %&gt;%
  rename(Sepal.Len.Width = sep.lw)

write_csv(my_modified_data, &quot;my_modified_data.csv&quot;)
&lt;/pre&gt;]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.datanovia.com/en/lessons/compute-and-add-new-variables-to-a-data-frame-in-r/#comment-1505">mangogul</a>.</p>
<p>It&#8217;s not virtual, you need to create a new R object to hold the modified data frame; then, you can save or manipulate the data again.</p>
<p>For example:</p>
<pre class = "r_code">
library(tidyverse)
my_modified_data <- iris %>%
  mutate(sep.lw = Sepal.Length*Sepal.Width) %>%
  rename(Sepal.Len.Width = sep.lw)

write_csv(my_modified_data, "my_modified_data.csv")
</pre>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: mangogul		</title>
		<link>https://www.datanovia.com/en/lessons/compute-and-add-new-variables-to-a-data-frame-in-r/#comment-1505</link>

		<dc:creator><![CDATA[mangogul]]></dc:creator>
		<pubDate>Sat, 03 Nov 2018 08:52:48 +0000</pubDate>
		<guid isPermaLink="false">https://www.datanovia.com/en/?post_type=dt_lessons&#038;p=7238#comment-1505</guid>

					<description><![CDATA[The new columns seem to be only virtual. For example, I cannot apply the rename function. Or when I write the dataframe as csv, the new column isn&#039;t present.

How can I force the variable to persist?]]></description>
			<content:encoded><![CDATA[<p>The new columns seem to be only virtual. For example, I cannot apply the rename function. Or when I write the dataframe as csv, the new column isn&#8217;t present.</p>
<p>How can I force the variable to persist?</p>
]]></content:encoded>
		
			</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/

Object Caching 104/187 objects using Memcached
Page Caching using Disk: Enhanced 
Lazy Loading (feed)
Database Caching 37/58 queries in 0.025 seconds using APC

Served from: www.datanovia.com @ 2025-07-31 03:13:53 by W3 Total Cache
-->