<?xml version="1.0" encoding="UTF-8" ?>
<!-- RSS generated by PHPBoost on Tue, 14 Apr 2026 01:17:14 +0200 -->

<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Last articles - STHDA : Tips & Tricks]]></title>
		<atom:link href="https://www.sthda.com/english/syndication/rss/articles/17" rel="self" type="application/rss+xml"/>
		<link>https://www.sthda.com</link>
		<description><![CDATA[Last articles - STHDA : Tips & Tricks]]></description>
		<copyright>(C) 2005-2026 PHPBoost</copyright>
		<language>en</language>
		<generator>PHPBoost</generator>
		
		
		<item>
			<title><![CDATA[Clear User Interface and Free Memory in R/RStudio]]></title>
			<link>https://www.sthda.com/english/articles/17-tips-tricks/75-clear-user-interface-and-free-memory-in-rrstudio/</link>
			<guid>https://www.sthda.com/english/articles/17-tips-tricks/75-clear-user-interface-and-free-memory-in-rrstudio/</guid>
			<description><![CDATA[Personally, to optimize the memory and work on a clean/fresh R/RStudio interface, I manage to start all my R scripts with this code:<br />
<br />
<div class="formatter-container formatter-code code-R"><span class="formatter-title">Code R :</span><div class="formatter-content"><pre style="display:inline;"><pre class="r" style="font-family:monospace;"><span style="color: #228B22;"># Clear plots</span>
<span style="color: #0000FF; font-weight: bold;">if</span><span style="color: #080;">&amp;#40;</span><span style="color: #080;">!</span><span style="color: #0000FF; font-weight: bold;">is.<span style="">null</span></span><span style="color: #080;">&amp;#40;</span><span style="color: #0000FF; font-weight: bold;">dev.<span style="">list</span></span><span style="color: #080;">&amp;#40;</span><span style="color: #080;">&amp;#41;</span><span style="color: #080;">&amp;#41;</span><span style="color: #080;">&amp;#41;</span> <span style="color: #0000FF; font-weight: bold;">dev.<span style="">off</span></span><span style="color: #080;">&amp;#40;</span><span style="color: #080;">&amp;#41;</span>
<span style="color: #228B22;"># Clear console</span>
<span style="color: #0000FF; font-weight: bold;">cat</span><span style="color: #080;">&amp;#40;</span><span style="color: #ff0000;">"<span style="color: #000099; font-weight: bold;">\0</span>14"</span><span style="color: #080;">&amp;#41;</span> 
<span style="color: #228B22;"># Clean workspace</span>
<span style="color: #0000FF; font-weight: bold;">rm</span><span style="color: #080;">&amp;#40;</span><span style="color: #0000FF; font-weight: bold;">list</span><span style="color: #080;">=</span><span style="color: #0000FF; font-weight: bold;">ls</span><span style="color: #080;">&amp;#40;</span><span style="color: #080;">&amp;#41;</span><span style="color: #080;">&amp;#41;</span>
<span style="color: #228B22;"># Set working directory</span>
<span style="color: #0000FF; font-weight: bold;">setwd</span><span style="color: #080;">&amp;#40;</span><span style="color: #ff0000;">"~/Downloads/MyScripts"</span><span style="color: #080;">&amp;#41;</span></pre></pre></div></div><br />
<br />
Let me explain the code line by line:<br />
<div class="formatter-container formatter-code code-R"><span class="formatter-title">Code R :</span><div class="formatter-content"><pre style="display:inline;"><pre class="r" style="font-family:monospace;"><span style="color: #0000FF; font-weight: bold;">if</span><span style="color: #080;">&amp;#40;</span><span style="color: #080;">!</span><span style="color: #0000FF; font-weight: bold;">is.<span style="">null</span></span><span style="color: #080;">&amp;#40;</span><span style="color: #0000FF; font-weight: bold;">dev.<span style="">list</span></span><span style="color: #080;">&amp;#40;</span><span style="color: #080;">&amp;#41;</span><span style="color: #080;">&amp;#41;</span><span style="color: #080;">&amp;#41;</span> <span style="color: #0000FF; font-weight: bold;">dev.<span style="">off</span></span><span style="color: #080;">&amp;#40;</span><span style="color: #080;">&amp;#41;</span></pre></pre></div></div><br />
<div class="indent">This is equivalent to click on the button clear all plots in the plots panel.<br />
</div><br />
<br />
<div class="formatter-container formatter-code code-R"><span class="formatter-title">Code R :</span><div class="formatter-content"><pre style="display:inline;"><pre class="r" style="font-family:monospace;"><span style="color: #0000FF; font-weight: bold;">cat</span><span style="color: #080;">&amp;#40;</span><span style="color: #ff0000;">"<span style="color: #000099; font-weight: bold;">\0</span>14"</span><span style="color: #080;">&amp;#41;</span> </pre></pre></div></div><br />
<div class="indent">This is identical to Ctrl+L or to click on the clear console within the Edit menu.</div><br />
<br />
<div class="formatter-container formatter-code code-R"><span class="formatter-title">Code R :</span><div class="formatter-content"><pre style="display:inline;"><pre class="r" style="font-family:monospace;"><span style="color: #0000FF; font-weight: bold;">rm</span><span style="color: #080;">&amp;#40;</span><span style="color: #0000FF; font-weight: bold;">list</span><span style="color: #080;">=</span><span style="color: #0000FF; font-weight: bold;">ls</span><span style="color: #080;">&amp;#40;</span><span style="color: #080;">&amp;#41;</span><span style="color: #080;">&amp;#41;</span></pre></pre></div></div><br />
<div class="indent">This is equivalent to click on the button clear objects from the workspace in the environment panel.<br />
</div><br />
<br />
These code lines allow to clear the panels and so free memory.<br />
<br />
<div class="formatter-container formatter-code code-R"><span class="formatter-title">Code R :</span><div class="formatter-content"><pre style="display:inline;"><pre class="r" style="font-family:monospace;"><span style="color: #0000FF; font-weight: bold;">setwd</span><span style="color: #080;">&amp;#40;</span><span style="color: #ff0000;">"~/Downloads/MyScripts"</span><span style="color: #080;">&amp;#41;</span></pre></pre></div></div><br />
<div class="indent">Here you set up your working directory, in my case (Linux Ubuntu user), I choose to use the directory Myscripts inside my Downloads directory. You could use your own path to the directory you want to use there.<br />
</div><br />
<br />
I hope this code would be helpful and you would choose to use it in your scripts.<br />
<br />
If anyone knows a code to clear the history, please let me know, i would integrate it to this article.]]></description>
			<pubDate>Sat, 26 Aug 2017 17:03:00 +0200</pubDate>
			
		</item>
		
		<item>
			<title><![CDATA[R: Find the Length of Every Elements in a List]]></title>
			<link>https://www.sthda.com/english/articles/17-tips-tricks/70-r-find-the-length-of-every-elements-in-a-list/</link>
			<guid>https://www.sthda.com/english/articles/17-tips-tricks/70-r-find-the-length-of-every-elements-in-a-list/</guid>
			<description><![CDATA[In <strong>R programming language</strong>, to find the <strong>length</strong> of every elements in a list,  the function <strong>lengths</strong>() can be used.<br />
<br />
A simplified format is as follow:<br />
<br />
<div class="formatter-container formatter-code code-R"><span class="formatter-title">Code R :</span><div class="formatter-content"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&amp;nbsp;
lengths<span style="color: #080;">&amp;#40;</span>x<span style="color: #080;">&amp;#41;</span>
&amp;nbsp;</pre></pre></div></div><br />
<br />
This function loops over x and returns a compatible vector containing the length of each element in x.<br />
<br />
For example:<br />
<br />
<div class="formatter-container formatter-code code-R"><span class="formatter-title">Code R :</span><div class="formatter-content"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&amp;nbsp;
my.<span style="">list</span> <span style="color: #080;"><-</span> <span style="color: #0000FF; font-weight: bold;">list</span><span style="color: #080;">&amp;#40;</span>name <span style="color: #080;">=</span> <span style="color: #0000FF; font-weight: bold;">c</span><span style="color: #080;">&amp;#40;</span><span style="color: #ff0000;">"A"</span>, <span style="color: #ff0000;">"B"</span>, <span style="color: #ff0000;">"C"</span><span style="color: #080;">&amp;#41;</span>, age <span style="color: #080;">=</span> <span style="color: #0000FF; font-weight: bold;">c</span><span style="color: #080;">&amp;#40;</span><span style="color: #ff0000;">20</span>, <span style="color: #ff0000;">30</span>, <span style="color: #ff0000;">40</span>, <span style="color: #ff0000;">50</span><span style="color: #080;">&amp;#41;</span><span style="color: #080;">&amp;#41;</span>
lengths<span style="color: #080;">&amp;#40;</span>my.<span style="">list</span><span style="color: #080;">&amp;#41;</span>
&amp;nbsp;</pre></pre></div></div><br />
<br />
Output:<br />
<br />
<!-- START HTML -->
<pre>
name  age 
   3    4 
</pre>
<!-- END HTML --><br />]]></description>
			<pubDate>Wed, 16 Aug 2017 13:10:00 +0200</pubDate>
			
		</item>
		
		<item>
			<title><![CDATA[What is Variable Loadings in PCA?]]></title>
			<link>https://www.sthda.com/english/articles/17-tips-tricks/68-what-is-variable-loadings-in-pcae/</link>
			<guid>https://www.sthda.com/english/articles/17-tips-tricks/68-what-is-variable-loadings-in-pcae/</guid>
			<description><![CDATA[<strong>Loadings</strong> are interpreted as the coefficients of the linear combination of the initial variables from which the <strong>principal components</strong> are constructed.<br />
<br />
From a numerical point of view, the loadings are equal to the coordinates of the variables divided by the square root of the <strong>eigenvalue</strong> associated with the component.<br />
<br />
The loadings are the default outputs of the functions <strong>princomp</strong>() and <strong>prcomp</strong>().<br />
<br />
<em>Source: Husson et al., Exploratory Multivariate Analysis by Examples Using R, 2011.</em>]]></description>
			<pubDate>Mon, 14 Aug 2017 16:31:00 +0200</pubDate>
			
		</item>
		
		<item>
			<title><![CDATA[dplyr: How to Add Cumulative Sums by Groups Into a Data Frame?]]></title>
			<link>https://www.sthda.com/english/articles/17-tips-tricks/57-dplyr-how-to-add-cumulative-sums-by-groups-into-a-data-framee/</link>
			<guid>https://www.sthda.com/english/articles/17-tips-tricks/57-dplyr-how-to-add-cumulative-sums-by-groups-into-a-data-framee/</guid>
			<description><![CDATA[To add into a data frame, the <strong>cumulative sum</strong> of a variable by groups, the syntax is as follow using the <strong>dplyr</strong> package and the iris demo data set:<br />
<br />
<div class="formatter-container formatter-code code-R"><span class="formatter-title">Code R :</span><div class="formatter-content"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&amp;nbsp;
<span style="color: #0000FF; font-weight: bold;">library</span><span style="color: #080;">&amp;#40;</span>dplyr<span style="color: #080;">&amp;#41;</span>
<span style="color: #CC9900; font-weight: bold;">iris</span> <span style="color: #080;">%>%</span>
  group_by<span style="color: #080;">&amp;#40;</span>Species<span style="color: #080;">&amp;#41;</span> <span style="color: #080;">%>%</span>
  mutate<span style="color: #080;">&amp;#40;</span>cum_sep_len <span style="color: #080;">=</span> <span style="color: #0000FF; font-weight: bold;">cumsum</span><span style="color: #080;">&amp;#40;</span>Sepal.<span style="">Length</span><span style="color: #080;">&amp;#41;</span><span style="color: #080;">&amp;#41;</span>
&amp;nbsp;</pre></pre></div></div><br />
<br />
Output:<br />
<br />
<!-- START HTML -->

<pre>
# A tibble: 150 x 6
# Groups:   Species [3]
   Sepal.Length Sepal.Width Petal.Length Petal.Width Species cum_sep_len
          <dbl>       <dbl>        <dbl>       <dbl>  <fctr>       <dbl>
 1          5.1         3.5          1.4         0.2  setosa         5.1
 2          4.9         3.0          1.4         0.2  setosa        10.0
 3          4.7         3.2          1.3         0.2  setosa        14.7
 4          4.6         3.1          1.5         0.2  setosa        19.3
 5          5.0         3.6          1.4         0.2  setosa        24.3
 6          5.4         3.9          1.7         0.4  setosa        29.7
 7          4.6         3.4          1.4         0.3  setosa        34.3
 8          5.0         3.4          1.5         0.2  setosa        39.3
 9          4.4         2.9          1.4         0.2  setosa        43.7
10          4.9         3.1          1.5         0.1  setosa        48.6
# ... with 140 more rows
</pre>

<!-- END HTML --><br />
<br />]]></description>
			<pubDate>Tue, 08 Aug 2017 16:50:00 +0200</pubDate>
			
		</item>
		
		<item>
			<title><![CDATA[How to Export Multiple ggplots Using a for Loop]]></title>
			<link>https://www.sthda.com/english/articles/17-tips-tricks/55-how-to-export-multiple-ggplots-using-a-for-loop/</link>
			<guid>https://www.sthda.com/english/articles/17-tips-tricks/55-how-to-export-multiple-ggplots-using-a-for-loop/</guid>
			<description><![CDATA[To <strong>save</strong> multiple ggplots using for loop, you need to call the function print() explicitly to plot a <strong>ggplot</strong> to a device such as PDF, PNG, JPG file.<br />
<br />
For example:<br />
<br />
<br />
<br />
<div class="formatter-container formatter-code code-R"><span class="formatter-title">Code R :</span><div class="formatter-content"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&amp;nbsp;
<span style="color: #0000FF; font-weight: bold;">library</span><span style="color: #080;">&amp;#40;</span>ggplot2<span style="color: #080;">&amp;#41;</span>
p <span style="color: #080;"><-</span> ggplot<span style="color: #080;">&amp;#40;</span><span style="color: #CC9900; font-weight: bold;">iris</span>, aes<span style="color: #080;">&amp;#40;</span>x <span style="color: #080;">=</span> Species, y <span style="color: #080;">=</span> Sepal.<span style="">Length</span><span style="color: #080;">&amp;#41;</span><span style="color: #080;">&amp;#41;</span>
<span style="color: #0000FF; font-weight: bold;">colors</span> <span style="color: #080;"><-</span> <span style="color: #0000FF; font-weight: bold;">c</span><span style="color: #080;">&amp;#40;</span><span style="color: #ff0000;">"black"</span>, <span style="color: #ff0000;">"red"</span>, <span style="color: #ff0000;">"green"</span><span style="color: #080;">&amp;#41;</span>
&amp;nbsp;
<span style="color: #0000FF; font-weight: bold;">for</span><span style="color: #080;">&amp;#40;</span>color <span style="color: #0000FF; font-weight: bold;">in</span> <span style="color: #0000FF; font-weight: bold;">colors</span><span style="color: #080;">&amp;#41;</span><span style="color: #080;">&amp;#123;</span>
&amp;nbsp;
   final.<span style="">plot</span> <span style="color: #080;"><-</span> p <span style="color: #080;">+</span> geom_boxplot<span style="color: #080;">&amp;#40;</span>color <span style="color: #080;">=</span> color<span style="color: #080;">&amp;#41;</span>
&amp;nbsp;
  <span style="color: #0000FF; font-weight: bold;">pdf</span><span style="color: #080;">&amp;#40;</span>paste0<span style="color: #080;">&amp;#40;</span>color, <span style="color: #ff0000;">".pdf"</span><span style="color: #080;">&amp;#41;</span><span style="color: #080;">&amp;#41;</span>
  <span style="color: #0000FF; font-weight: bold;">print</span><span style="color: #080;">&amp;#40;</span>final.<span style="">plot</span><span style="color: #080;">&amp;#41;</span>
  <span style="color: #0000FF; font-weight: bold;">dev.<span style="">off</span></span><span style="color: #080;">&amp;#40;</span><span style="color: #080;">&amp;#41;</span>
<span style="color: #080;">&amp;#125;</span>
&amp;nbsp;</pre></pre></div></div><br />
<br />]]></description>
			<pubDate>Sat, 05 Aug 2017 21:16:00 +0200</pubDate>
			
		</item>
		
		<item>
			<title><![CDATA[Open Multiple Independent Rstudio Sessions in Mac OS X]]></title>
			<link>https://www.sthda.com/english/articles/17-tips-tricks/31-open-multiple-independent-rstudio-sessions-in-mac-os-x/</link>
			<guid>https://www.sthda.com/english/articles/17-tips-tricks/31-open-multiple-independent-rstudio-sessions-in-mac-os-x/</guid>
			<description><![CDATA[To open multiple independent R sessions in Mac OSX, type the following bash command in the UNIX Terminal:<br />
<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH :</span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&amp;nbsp;
open <span style="color: #660033;">-n</span> <span style="color: #660033;">-a</span> <span style="color: #ff0000;">"Rstudio"</span>
&amp;nbsp;</pre></pre></div></div>]]></description>
			<pubDate>Thu, 27 Jul 2017 11:42:00 +0200</pubDate>
			
		</item>
		
	</channel>
</rss>
