tag:blogger.com,1999:blog-74984852871296535602024-02-20T22:43:00.692-08:00Big Data Science/Calcul Scientifique/Programming and Scientific ComputingBlog sur le Big Data Science/Programmation et Calcul Scientifique/Programming and Scientific Computing pour partage de solutions en calcul scientifique. Let's share simple ways for processing Big Data, Programming and Scientific Computing.Mbaye Babacarhttp://www.blogger.com/profile/02966697191958511560noreply@blogger.comBlogger9125tag:blogger.com,1999:blog-7498485287129653560.post-90060243998310821202015-07-16T08:57:00.001-07:002015-07-16T08:57:28.803-07:00Netcdf in R. Part 1: Installation in Linux debian based (ubuntu, linux mint)Many scientific data (remoted sensed data, environmental, etc..) are distributed in NetCDF (nc format, .nc).<br />
In R, the most used package to process these data is ncdf4 but it requires some other LINUX packages to be installed correctly in R.<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhfxTS7cWnNAHbJqnv_KxwiTqrdyy3egcRPxRNBFs5WskROCAHpViyECMSyOTPG0LBGbR2j4jIm0_A3A_NzrRXOzbroZ-aKO1y3cnqqYCemiXnwkZQW2JscpowDfGQ3_1twuOoiBLoPCng/s1600/r_ncdf4.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="200" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhfxTS7cWnNAHbJqnv_KxwiTqrdyy3egcRPxRNBFs5WskROCAHpViyECMSyOTPG0LBGbR2j4jIm0_A3A_NzrRXOzbroZ-aKO1y3cnqqYCemiXnwkZQW2JscpowDfGQ3_1twuOoiBLoPCng/s320/r_ncdf4.png" width="320" /></a></div>
<br />
<br />
The required packages are <span style="font-family: "Helvetica Neue",Arial,Helvetica,sans-serif;"><i>libnetcdf-dev, libnetcdfc++4, libnetcdfc7, libnetcdff5, libcf0, netcdf-bin</i></span><br />
<br />
<span style="font-family: inherit;">These required packages can be installed using apt-get install, Synaptic or Software Manager. If they aren't installed you can have errors such if you try to install ndcf4 in R</span><br />
<br />
<span style="font-family: "Helvetica Neue",Arial,Helvetica,sans-serif;"><i>ERROR: configuration failed for package ‘ncdf4’ </i></span><br />
<br />
<span style="font-family: "Helvetica Neue",Arial,Helvetica,sans-serif;"><i>ncdf.c:3:20: fatal error: netcdf.h: No such file or directory<br /> #include <netcdf.h><br /> ^<br />compilation terminated.<br />make: *** [ncdf.o] Error 1<br />ERROR: compilation failed for package ‘ncdf4’</i></span><br />
<span style="font-family: inherit;"><i><br /></i></span>
<span style="font-family: inherit;">After installing these requirements you can install now ncdf4 in R (install.packages('ncdf4')</span><br />
<br />
<span style="font-family: inherit;">In the next post, I'll give some useful tips to explore ncdf files in R.</span><br />
<span style="font-family: "Helvetica Neue",Arial,Helvetica,sans-serif;"><i><span style="font-family: inherit;"> </span></i></span><br />
<span style="font-family: "Helvetica Neue",Arial,Helvetica,sans-serif;"><i> </i></span><br />
<span style="font-family: "Helvetica Neue",Arial,Helvetica,sans-serif;"><i> </i></span>Mbaye Babacarhttp://www.blogger.com/profile/02966697191958511560noreply@blogger.com0tag:blogger.com,1999:blog-7498485287129653560.post-66117860993214645882015-01-24T00:06:00.000-08:002015-01-24T00:06:17.056-08:00Revolution Analytics joins Microsoft: Microsoft prête à engager réellement le combat dans les "Big" Data Science? <br />
<em> David Smith, Chief Community Officer, says on this blog</em><br />
"On behalf of the entire Revolution Analytics team I am excited to
announce that Revolution Analytics is joining forces with Microsoft to
bring R to even more enterprises. Microsoft <a href="http://blogs.microsoft.com/?p=46261">announced today that it will acquire Revolution Analytics</a>."<br />
<br />
More... http://blog.revolutionanalytics.com/2015/01/revolution-acquired.html <br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi75H3IUmSVt8HHWQrHThiXeYHxYTA8uigeOR70-vJf_nSJa2fcGt9V-nFZ5Qxjc9WMaSXbOi4tO98Q6xtm1Iepu3crSRHzwCdXNV-dWZAY7R1bY1qvZ7Om45McJN1vKqi7HGjTTv76Vv8/s1600/microsoftRAnalytics.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi75H3IUmSVt8HHWQrHThiXeYHxYTA8uigeOR70-vJf_nSJa2fcGt9V-nFZ5Qxjc9WMaSXbOi4tO98Q6xtm1Iepu3crSRHzwCdXNV-dWZAY7R1bY1qvZ7Om45McJN1vKqi7HGjTTv76Vv8/s1600/microsoftRAnalytics.png" height="89" width="320" /></a></div>
<br />Mbaye Babacarhttp://www.blogger.com/profile/02966697191958511560noreply@blogger.com0tag:blogger.com,1999:blog-7498485287129653560.post-65653680432223457152014-07-31T03:04:00.000-07:002014-07-31T03:10:32.704-07:00Matlab, eval: Dynamic variable naming with eval/Création dynamique de variablesThe purpose is to dynamically name variables. Example: I wish to store the value returned by a function (<i><b>func</b></i>) in different variables according to a parameter <b style="font-style: italic;">i. /</b><br />
<b style="font-style: italic;">[french] le </b>but de la manoeuvre est de créer dynamiquement des variables (avec des noms dynamiques). Exemple, je souhaite stocker les valeurs retournées par une fonction dans différentes variables en fonction de la valeur d'un paramètre.<b style="font-style: italic;">[/french]</b><br />
Basically<br />
<i><span style="font-family: Courier New, Courier, monospace;"><b style="background-color: #eeeeee;">for i=1:10</b></span></i><br />
<i><span style="font-family: Courier New, Courier, monospace;"><b style="background-color: #eeeeee;"> a=func(param1, param2,i); (exemple a=sin(i*pi));</b></span></i><br />
<i><span style="font-family: Courier New, Courier, monospace;"><b style="background-color: #eeeeee;">end</b></span></i><br />
<br />
Of course in this way <b><i>a</i></b> is always overwritten./ Dans cette solution la variable <b><i>a</i></b> est toujours écrasé.<br />
<br />
If I want to dynamically create variables and store the different returned values in these variables, I can us eval<br />
<b style="font-style: italic;">[french]</b>Si je veux créer dynamiquement les variables, j'utilise la fonction eval<b style="font-style: italic;">[/french]</b><br />
<br />
<i><span style="background-color: #eeeeee; font-family: Courier New, Courier, monospace;"><b>for i=1:10</b></span></i><br />
<i><span style="background-color: #eeeeee; font-family: Courier New, Courier, monospace;"><b> val=strcat('a',num2str(i))</b></span></i><br />
<i><span style="background-color: #eeeeee; font-family: Courier New, Courier, monospace;"><b> a=func(param1, param2,i);</b></span></i><i><span style="font-family: Courier New, Courier, monospace;"><b style="background-color: #eeeeee;">(exemple a=sin(i*pi));</b></span></i><br />
<i><span style="background-color: #eeeeee; font-family: Courier New, Courier, monospace;"><b> eval([val'=a;'])</b></span></i><br />
<i><span style="background-color: #eeeeee; font-family: Courier New, Courier, monospace;"><b>end</b></span></i><br />
<br />
If this way, the 10 returned values will be stored in a1, a2, ....,a10<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEga5bYZuurVujIpxCt7Qs9nile-5vC8Xwfx7PLUMDo3bJZpCeEqwpONmDS91q5sXqgyShmYH-q1SQrxPbjVug9s2MANH8BeIotK-DeflSxpi9cReEaNSTIMfqJu4qfHorppG1cEObP4uQs/s1600/bg_header_mwlogo_notag.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEga5bYZuurVujIpxCt7Qs9nile-5vC8Xwfx7PLUMDo3bJZpCeEqwpONmDS91q5sXqgyShmYH-q1SQrxPbjVug9s2MANH8BeIotK-DeflSxpi9cReEaNSTIMfqJu4qfHorppG1cEObP4uQs/s1600/bg_header_mwlogo_notag.jpg" /></a></div>
<br />
<br />Mbaye Babacarhttp://www.blogger.com/profile/02966697191958511560noreply@blogger.com0tag:blogger.com,1999:blog-7498485287129653560.post-73245225756961523532014-05-21T07:11:00.001-07:002014-05-21T07:12:13.103-07:00Windows change directory to no system drive (cd another drive) using cmd, command line, promptHello!<br />
We use cd to change directory but if the directory is not on the system partition, there is no change. To overcome just add <span style="background-color: #999999;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><i>/d</i></span> </span>after the cd.<br />
If I want to change to a directory named folder1 in drive f using command line i do:<br />
<i style="background-color: #cccccc;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">cd /d E:/folder1</span></i>Mbaye Babacarhttp://www.blogger.com/profile/02966697191958511560noreply@blogger.com0tag:blogger.com,1999:blog-7498485287129653560.post-44970608355474928322013-12-27T10:28:00.004-08:002013-12-27T10:34:49.111-08:00elsarticle: psyr at 12.0pt not loadable: Metric (TFM) file not found for Ubuntu, Mint using Kile<br />
I had this problem while compiling a latex document based on the Elsevier latex article class with kile-texlive<br />
<br />
<i style="background-color: #eeeeee;">font u/psy/m/n/12=psyr at 12.0pt not loadable metric (tfm) file not found</i><br />
I found a solution with lof of matters. I share it here! Type in a command windows<br />
<br />
<i style="background-color: #eeeeee;">sudo apt-get install texlive-fonts-recommended</i><br />
<br />
<div class="separator" style="clear: both;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjvwGOpGP645KUNB-l5rfFKMvqX7w4egolHYWzz8GIUnalJGJ5IOhWmCuNRWjRNlqJXIoKZl8e5HitjgOCab9JZWTzxVPMjuiadUBTp7Nb52xH134g4RgLzQ2xqRKb3E7z1eNIc-vJkhps/s1600/elsevier2.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjvwGOpGP645KUNB-l5rfFKMvqX7w4egolHYWzz8GIUnalJGJ5IOhWmCuNRWjRNlqJXIoKZl8e5HitjgOCab9JZWTzxVPMjuiadUBTp7Nb52xH134g4RgLzQ2xqRKb3E7z1eNIc-vJkhps/s1600/elsevier2.jpg" /></a></div>
<br />
Hoping that would be helpful for someone.Mbaye Babacarhttp://www.blogger.com/profile/02966697191958511560noreply@blogger.com0tag:blogger.com,1999:blog-7498485287129653560.post-47889310563605715892013-02-26T11:00:00.002-08:002013-02-26T11:08:23.013-08:00Matlab: plot, imagesc, graphical options don't work.<div>
Graphical options (properties) such as fontsize, font weight and so are not considered, only default graphical properties are displayed in linux ubuntu 10.04+<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh4aJH0eNi51tUNYcyAsL5kZJMi5Q3Q_f13VpsXuasr20I9V89193zSanXnnOOPwB3Yl1H_5NGCEJOu3cYb0nA7vKgcQm2IWAcrbQWBlpoKY49DkifCifHpWwLS6SBZ4-S6u3flEZaNaNE/s1600/ubuntu_matlab.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh4aJH0eNi51tUNYcyAsL5kZJMi5Q3Q_f13VpsXuasr20I9V89193zSanXnnOOPwB3Yl1H_5NGCEJOu3cYb0nA7vKgcQm2IWAcrbQWBlpoKY49DkifCifHpWwLS6SBZ4-S6u3flEZaNaNE/s1600/ubuntu_matlab.jpg" /></a></div>
<br /></div>
<div>
How to solve this problem?</div>
<div>
The solution I propposed here worked for me. </div>
<div>
Since 11.11 release (with update to 10.04 and ..) Ubuntu <span style="background-color: white; font-family: arial, sans-serif; font-size: 13px; white-space: nowrap;">switch</span> to OpenJDK replacing Oracle (Sun) JDK,JRE.</div>
<div>
Since this changing graphical properties in Matlab don't work correctly (in my case). To solve this problem I replace my JDK, JRE from OpenJDK to Oracle JDK using the following </div>
<div>
<br /></div>
<div>
<br /></div>
<div>
(source <a href="http://www.ubuntugeek.com/how-to-install-oracle-java-7-in-ubuntu-12-04.html" target="_blank">http://www.ubuntugeek.com/</a>)</div>
<div>
<br /></div>
<div>
<div style="background-color: white; border: 0px; font-family: Tahoma, Arial, Helvetica; font-size: 12px; line-height: 20px; margin-bottom: 10px; outline: 0px; padding: 0px; text-align: justify; text-indent: 20px; vertical-align: baseline;">
<strong style="background-color: transparent; border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">Preparing your system</strong></div>
<div style="background-color: white; border: 0px; font-family: Tahoma, Arial, Helvetica; font-size: 12px; line-height: 20px; margin-bottom: 10px; outline: 0px; padding: 0px; text-align: justify; text-indent: 20px; vertical-align: baseline;">
First you need to remove openjdk for this run the following command from your terminal</div>
<blockquote style="background-color: white; border: 1px dashed rgb(102, 102, 102); font-family: Tahoma, Arial, Helvetica; font-size: 12px; line-height: 20px; margin: 0px; outline: 0px; padding: 10px 20px; quotes: none; text-align: justify; vertical-align: baseline;">
<div style="background-color: transparent; border: 0px; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;">
sudo apt-get purge openjdk*</div>
</blockquote>
<div style="background-color: white; border: 0px; font-family: Tahoma, Arial, Helvetica; font-size: 12px; line-height: 20px; margin-bottom: 10px; outline: 0px; padding: 0px; text-align: justify; vertical-align: baseline;">
If you installed java 7 from any other PPA and you are having problem with java then you have to do following steps before installing the PPA menctioned here</div>
<blockquote style="background-color: white; border: 1px dashed rgb(102, 102, 102); font-family: Tahoma, Arial, Helvetica; font-size: 12px; line-height: 20px; margin: 0px; outline: 0px; padding: 10px 20px; quotes: none; text-align: justify; vertical-align: baseline;">
<div style="background-color: transparent; border: 0px; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;">
sudo rm /var/lib/dpkg/info/oracle-java7-installer*<br />
sudo apt-get purge oracle-java7-installer*<br />
sudo rm /etc/apt/sources.list.d/*java*<br />
sudo apt-get update</div>
</blockquote>
<div style="background-color: white; border: 0px; font-family: Tahoma, Arial, Helvetica; font-size: 12px; line-height: 20px; margin-bottom: 10px; outline: 0px; padding: 0px; text-align: justify; vertical-align: baseline;">
<strong style="background-color: transparent; border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">Install oracle java 7 in ubuntu 12.04</strong></div>
<div style="background-color: white; border: 0px; font-family: Tahoma, Arial, Helvetica; font-size: 12px; line-height: 20px; margin-bottom: 10px; outline: 0px; padding: 0px; text-align: justify; text-indent: 20px; vertical-align: baseline;">
Open the terminal and run the following commands</div>
<blockquote style="background-color: white; border: 1px dashed rgb(102, 102, 102); font-family: Tahoma, Arial, Helvetica; font-size: 12px; line-height: 20px; margin: 0px; outline: 0px; padding: 10px 20px; quotes: none; text-align: justify; vertical-align: baseline;">
<div style="background-color: transparent; border: 0px; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;">
sudo add-apt-repository ppa:webupd8team/java<br />
sudo apt-get update<br />
sudo apt-get install oracle-java7-installer</div>
</blockquote>
<div style="background-color: white; border: 0px; font-family: Tahoma, Arial, Helvetica; font-size: 12px; line-height: 20px; margin-bottom: 10px; outline: 0px; padding: 0px; text-align: justify; vertical-align: baseline;">
You can check the java version by searching java in dashboard</div>
<div style="background-color: white; border: 0px; font-family: Tahoma, Arial, Helvetica; font-size: 12px; line-height: 20px; margin-bottom: 10px; outline: 0px; padding: 0px; text-align: justify; text-indent: 20px; vertical-align: baseline;">
<a href="http://www.ubuntugeek.com/wp-content/uploads/2012/03/1.png" style="background-color: transparent; border: 0px; color: #d90d19; margin: 0px; outline: 0px; padding: 0px; text-decoration: none; vertical-align: baseline;"><img alt="" class="alignnone size-full wp-image-13050" src="http://www.ubuntugeek.com/wp-content/uploads/2012/03/1.png" height="493" style="background-color: transparent; border: 1px solid rgb(238, 238, 238); margin: 5px; max-width: 90%; outline: 0px; padding: 5px; vertical-align: baseline;" title="1" width="406" /></a></div>
</div>
Mbaye Babacarhttp://www.blogger.com/profile/02966697191958511560noreply@blogger.com0tag:blogger.com,1999:blog-7498485287129653560.post-72428288572122362452012-11-21T04:11:00.000-08:002012-11-21T04:11:10.123-08:00 R code for listing directories/code R pour lister les repertoires<div>
<br /></div>
<div>
<div style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Times New Roman;"><span style="font-size: medium;">Here
is a pretty R code for listing directories in a
given directory</span></span></span></div>
<div style="margin-bottom: 0.5cm;">
<span style="color: black;"><span style="font-family: Times New Roman;"><span style="font-size: medium;">Voici
un code R pour lister les repertoires d'un dossier donné</span></span></span></div>
<pre style="background-color: #eeeeee; background-position: initial initial; background-repeat: initial initial; border: none; line-height: 0.48cm; padding: 0cm;"><code><span style="color: black;"><span style="font-family: Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, serif;"><span style="font-size: x-small;"><span style="background: transparent;">list.dirs <- </span></span></span></span></code><code><span style="color: darkblue;"><span style="font-family: Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, serif;"><span style="font-size: x-small;"><span style="background: transparent;">function</span></span></span></span></code><code><span style="color: black;"><span style="font-family: Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, serif;"><span style="font-size: x-small;"><span style="background: transparent;">(path=</span></span></span></span></code><code><span style="color: maroon;"><span style="font-family: Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, serif;"><span style="font-size: x-small;"><span style="background: transparent;">"."</span></span></span></span></code><code><span style="color: black;"><span style="font-family: Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, serif;"><span style="font-size: x-small;"><span style="background: transparent;">,recursive=FALSE) {</span></span></span></span></code>
<code><span style="color: black;"><span style="background: transparent;"> </span></span></code><code><span style="color: darkblue;"><span style="font-family: Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, serif;"><span style="font-size: x-small;"><span style="background: transparent;">get</span></span></span></span></code><code><span style="color: black;"><span style="font-family: Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, serif;"><span style="font-size: x-small;"><span style="background: transparent;">.list <- list.files(path)</span></span></span></span></code>
<code><span style="color: black;"><span style="background: transparent;"> </span></span></code><code><span style="color: darkblue;"><span style="font-family: Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, serif;"><span style="font-size: x-small;"><span style="background: transparent;">if</span></span></span></span></code><code><span style="color: black;"><span style="font-family: Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, serif;"><span style="font-size: x-small;"><span style="background: transparent;"> (length(</span></span></span></span></code><code><span style="color: darkblue;"><span style="font-family: Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, serif;"><span style="font-size: x-small;"><span style="background: transparent;">get</span></span></span></span></code><code><span style="color: black;"><span style="font-family: Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, serif;"><span style="font-size: x-small;"><span style="background: transparent;">.list) == </span></span></span></span></code><code><span style="color: maroon;"><span style="font-family: Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, serif;"><span style="font-size: x-small;"><span style="background: transparent;">0</span></span></span></span></code><code><span style="color: black;"><span style="font-family: Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, serif;"><span style="font-size: x-small;"><span style="background: transparent;">) {</span></span></span></span></code><code><span style="color: darkblue;"><span style="font-family: Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, serif;"><span style="font-size: x-small;"><span style="background: transparent;">return</span></span></span></span></code><code><span style="color: black;"><span style="font-family: Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, serif;"><span style="font-size: x-small;"><span style="background: transparent;">(NULL)} </span></span></span></span></code><code><span style="color: grey;"><span style="font-family: Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, serif;"><span style="font-size: x-small;"><span style="background: transparent;">#no files or directories</span></span></span></span></code>
<code><span style="color: black;"><span style="background: transparent;"> </span></span></code><code><span style="color: darkblue;"><span style="font-family: Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, serif;"><span style="font-size: x-small;"><span style="background: transparent;">get</span></span></span></span></code><code><span style="color: black;"><span style="font-family: Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, serif;"><span style="font-size: x-small;"><span style="background: transparent;">.list.</span></span></span></span></code><code><span style="color: darkblue;"><span style="font-family: Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, serif;"><span style="font-size: x-small;"><span style="background: transparent;">fixed</span></span></span></span></code><code><span style="color: black;"><span style="font-family: Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, serif;"><span style="font-size: x-small;"><span style="background: transparent;"> <- paste(path,</span></span></span></span></code><code><span style="color: darkblue;"><span style="font-family: Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, serif;"><span style="font-size: x-small;"><span style="background: transparent;">get</span></span></span></span></code><code><span style="color: black;"><span style="font-family: Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, serif;"><span style="font-size: x-small;"><span style="background: transparent;">.list,sep=</span></span></span></span></code><code><span style="color: maroon;"><span style="font-family: Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, serif;"><span style="font-size: x-small;"><span style="background: transparent;">"/"</span></span></span></span></code><code><span style="color: black;"><span style="font-family: Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, serif;"><span style="font-size: x-small;"><span style="background: transparent;">)</span></span></span></span></code>
<code><span style="color: black;"><span style="background: transparent;"> </span></span></code><code><span style="color: black;"><span style="font-family: Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, serif;"><span style="font-size: x-small;"><span style="background: transparent;">whichonesaredir <- file.info(</span></span></span></span></code><code><span style="color: darkblue;"><span style="font-family: Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, serif;"><span style="font-size: x-small;"><span style="background: transparent;">get</span></span></span></span></code><code><span style="color: black;"><span style="font-family: Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, serif;"><span style="font-size: x-small;"><span style="background: transparent;">.list.</span></span></span></span></code><code><span style="color: darkblue;"><span style="font-family: Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, serif;"><span style="font-size: x-small;"><span style="background: transparent;">fixed</span></span></span></span></code><code><span style="color: black;"><span style="font-family: Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, serif;"><span style="font-size: x-small;"><span style="background: transparent;">)$isdir</span></span></span></span></code>
<code><span style="color: black;"><span style="background: transparent;"> </span></span></code><code><span style="color: darkblue;"><span style="font-family: Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, serif;"><span style="font-size: x-small;"><span style="background: transparent;">if</span></span></span></span></code><code><span style="color: black;"><span style="font-family: Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, serif;"><span style="font-size: x-small;"><span style="background: transparent;"> (!any(whichonesaredir)) {</span></span></span></span></code><code><span style="color: darkblue;"><span style="font-family: Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, serif;"><span style="font-size: x-small;"><span style="background: transparent;">return</span></span></span></span></code><code><span style="color: black;"><span style="font-family: Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, serif;"><span style="font-size: x-small;"><span style="background: transparent;">(NULL)} </span></span></span></span></code><code><span style="color: grey;"><span style="font-family: Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, serif;"><span style="font-size: x-small;"><span style="background: transparent;">#no directories, only files</span></span></span></span></code>
<code><span style="color: black;"><span style="background: transparent;"> </span></span></code><code><span style="color: black;"><span style="font-family: Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, serif;"><span style="font-size: x-small;"><span style="background: transparent;">dirlist <- </span></span></span></span></code><code><span style="color: darkblue;"><span style="font-family: Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, serif;"><span style="font-size: x-small;"><span style="background: transparent;">get</span></span></span></span></code><code><span style="color: black;"><span style="font-family: Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, serif;"><span style="font-size: x-small;"><span style="background: transparent;">.list.</span></span></span></span></code><code><span style="color: darkblue;"><span style="font-family: Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, serif;"><span style="font-size: x-small;"><span style="background: transparent;">fixed</span></span></span></span></code><code><span style="color: black;"><span style="font-family: Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, serif;"><span style="font-size: x-small;"><span style="background: transparent;">[whichonesaredir]</span></span></span></span></code>
<code><span style="color: black;"><span style="background: transparent;"> </span></span></code><code><span style="color: black;"><span style="font-family: Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, serif;"><span style="font-size: x-small;"><span style="background: transparent;">finaldirlist <- dirlist</span></span></span></span></code>
<code><span style="color: black;"><span style="background: transparent;"> </span></span></code><code><span style="color: darkblue;"><span style="font-family: Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, serif;"><span style="font-size: x-small;"><span style="background: transparent;">if</span></span></span></span></code><code><span style="color: black;"><span style="font-family: Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, serif;"><span style="font-size: x-small;"><span style="background: transparent;"> ((recursive & length(dirlist) > </span></span></span></span></code><code><span style="color: maroon;"><span style="font-family: Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, serif;"><span style="font-size: x-small;"><span style="background: transparent;">0</span></span></span></span></code><code><span style="color: black;"><span style="font-family: Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, serif;"><span style="font-size: x-small;"><span style="background: transparent;">)) {</span></span></span></span></code>
<code><span style="color: black;"><span style="background: transparent;"> </span></span></code><code><span style="color: darkblue;"><span style="font-family: Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, serif;"><span style="font-size: x-small;"><span style="background: transparent;">for</span></span></span></span></code><code><span style="color: black;"><span style="font-family: Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, serif;"><span style="font-size: x-small;"><span style="background: transparent;"> (i </span></span></span></span></code><code><span style="color: darkblue;"><span style="font-family: Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, serif;"><span style="font-size: x-small;"><span style="background: transparent;">in</span></span></span></span></code><code><span style="color: black;"><span style="font-family: Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, serif;"><span style="font-size: x-small;"><span style="background: transparent;"> </span></span></span></span></code><code><span style="color: maroon;"><span style="font-family: Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, serif;"><span style="font-size: x-small;"><span style="background: transparent;">1</span></span></span></span></code><code><span style="color: black;"><span style="font-family: Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, serif;"><span style="font-size: x-small;"><span style="background: transparent;">:length(dirlist)) {</span></span></span></span></code>
<code><span style="color: black;"><span style="background: transparent;"> </span></span></code><code><span style="color: black;"><span style="font-family: Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, serif;"><span style="font-size: x-small;"><span style="background: transparent;">finaldirlist <- c(finaldirlist,list.dirs(dirlist[i],recursive))</span></span></span></span></code>
<code><span style="color: black;"><span style="background: transparent;"> </span></span></code><code><span style="color: black;"><span style="font-family: Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, serif;"><span style="font-size: x-small;"><span style="background: transparent;">}</span></span></span></span></code>
<code><span style="color: black;"><span style="background: transparent;"> </span></span></code><code><span style="color: black;"><span style="font-family: Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, serif;"><span style="font-size: x-small;"><span style="background: transparent;">}</span></span></span></span></code>
<code><span style="color: black;"><span style="background: transparent;"> </span></span></code><code><span style="color: darkblue;"><span style="font-family: Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, serif;"><span style="font-size: x-small;"><span style="background: transparent;">return</span></span></span></span></code><code><span style="color: black;"><span style="font-family: Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, serif;"><span style="font-size: x-small;"><span style="background: transparent;">(finaldirlist)</span></span></span></span></code>
<code><span style="color: black;"><span style="font-family: Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, serif;"><span style="font-size: x-small;"><span style="background: transparent;">}</span></span></span></span></code></pre>
<div style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Times New Roman;"><span style="font-size: medium;">Save
the code in a file (listDir.r for example) and in R console
use the following commands </span></span></span></div>
<pre style="background-color: #eeeeee; background-position: initial initial; background-repeat: initial initial; border: none; line-height: 0.48cm; padding: 0cm;"><code><span style="color: black;"><span style="font-family: Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, serif;"><span style="font-size: x-small;"><span style="background: transparent;">source('listDir.r') #to source the file</span></span></span></span></code>
<code><span style="color: black;"><span style="font-family: Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, serif;"><span style="font-size: x-small;"><span style="background: transparent;">list=list.dirs(path,rec)#path is the current path by default else the dir in path will be listed. </span></span></span></span></code>
<code><span style="color: black;"><span style="font-family: Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, serif;"><span style="font-size: x-small;"><span style="background: transparent;">#rec (TRUE or FALSE(defaulty)) indicates if the sub-directories will be listed or not</span></span></span></span></code></pre>
</div>
<div>
<br /></div>
<div>
<br /></div>
<div>
source:<a href="http://stackoverflow.com/questions/4749783/how-to-obtain-a-list-of-directories-within-a-directory-like-list-files-but-i">http://stackoverflow.com/questions/4749783/how-to-obtain-a-list-of-directories-within-a-directory-like-list-files-but-i</a></div>
Mbaye Babacarhttp://www.blogger.com/profile/02966697191958511560noreply@blogger.com0tag:blogger.com,1999:blog-7498485287129653560.post-59659800032880975062012-09-26T04:42:00.002-07:002013-04-16T04:55:51.265-07:00simple way to compute rmse root mean square error in Rcalculer rmse ("racine" de l'erreur moyenne quadratique) avec R.<br />
<br />
<i>rmse=function(obs,pred)<br />{<br /> diff=obs-pred<br /> diff=diff[!is.na(diff)] #to remove NA values<br /> return (sqrt(mean((diff)^2)))<br />}</i><br />
save the commands above in a file named <i>rmse.r</i><br />
To call this function:<br />
considering that <i>obs</i> is the array of observed values, <i>pred </i>is the array of predicted values<br />
do<br />
<br />
source("<i>rmse.r</i>")<br />
rmsErr= <i>rmse(</i><i><i>obs,</i></i><i><i>pred</i>)</i><br />
<br />Mbaye Babacarhttp://www.blogger.com/profile/02966697191958511560noreply@blogger.com8tag:blogger.com,1999:blog-7498485287129653560.post-58952255134370929582012-08-23T10:09:00.000-07:002012-08-23T10:25:30.637-07:00plot two histograms together in R<pre class="default prettyprint"><code><span class="pln">Considering two samples of datas A and B. To plot histograms together in the same window </span></code></pre>
<pre class="default prettyprint"><code><span class="pln">just run the following commands (in the R Console) </span></code></pre>
<pre class="default prettyprint"><code><span class="pln"> </span></code></pre>
<pre class="default prettyprint"><i style="background-color: #eeeeee; font-family: "Courier New",Courier,monospace;"><code><span class="pln">hist</span><span class="pun">(</span><span class="pln">A</span><span class="pun">,</span><span class="pln"></span><span class="pun"></span><span class="pln"></span><span class="pun"></span><span class="lit"></span><span class="pun"></span><span class="lit"></span><span class="pun"></span><span class="pln">col</span><span class="pun">=</span><span class="str">"red"</span><span class="pun">)</span><span class="pln">
hist</span><span class="pun">(</span><span class="pln">B</span><span class="pun">,</span><span class="pln"></span><span class="pun"></span><span class="pln"> col</span><span class="pun">=</span><span class="pln">"blue",</span></code><code><span class="pln">add</span><span class="pun">=</span><span class="pln">T</span><span class="pun">)</span></code></i>
</pre>
<pre class="default prettyprint"><code><span class="pln"> </span></code></pre>
<pre class="default prettyprint"><code><span class="pln">Example: </span></code></pre>
<pre class="default prettyprint"><code><span class="pln"> </span></code></pre>
<pre class="default prettyprint"><i style="font-family: "Courier New",Courier,monospace;"><code style="background-color: #eeeeee;"><span class="pln">b=rnorm(2000, 6, 1)
a=rnorm(2000, 3, 1)</span></code></i></pre>
<pre class="default prettyprint"><i style="font-family: "Courier New",Courier,monospace;"><code style="background-color: #eeeeee;"><span class="pln">hist(a,col="red",ylim=c(0,400))</span></code></i></pre>
<pre class="default prettyprint"><i style="font-family: "Courier New",Courier,monospace;"><code style="background-color: #eeeeee;"><span class="pln">hist(b,col="blue",ylim=c(0,400),add=T) </span></code></i><code><i style="font-family: "Courier New",Courier,monospace;"><span class="pun" style="background-color: #eeeeee;"> # add=T is the key</span></i></code></pre>
<pre class="default prettyprint"><code><i style="font-family: "Courier New",Courier,monospace;"><span class="pun" style="background-color: #eeeeee;"> </span></i></code></pre>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEinnQx_Eejzm-YiLYvPgGvqwAYJBWxeSfmjPrPhfhHdWkoImRboyw176LDZY7sJhkntHnvgp2rC-EnXiL9sHvEWEqN24iupXFKcqwceM40HkTfA2PtuL2gwfIZMDvx2NdX4w9SBDwH7C5g/s1600/bihist.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="231" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEinnQx_Eejzm-YiLYvPgGvqwAYJBWxeSfmjPrPhfhHdWkoImRboyw176LDZY7sJhkntHnvgp2rC-EnXiL9sHvEWEqN24iupXFKcqwceM40HkTfA2PtuL2gwfIZMDvx2NdX4w9SBDwH7C5g/s400/bihist.jpg" width="400" /></a></div>
<pre class="default prettyprint"><code><i style="font-family: "Courier New",Courier,monospace;"><span class="pun" style="background-color: #eeeeee;"><span style="background-color: white;"></span></span></i><span class="pun"></span><span class="pln">
</span></code></pre>
Mbaye Babacarhttp://www.blogger.com/profile/02966697191958511560noreply@blogger.com0