<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/r-weekly-bulletin-vol-xiv/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://www.quantinsti.com/blog/r-weekly-bulletin-vol-xiv/"> R programming</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p><img sizes="(max-width: 1200px) 100vw, 1200px" src="https://i0.wp.com/www.quantinsti.com/wp-content/uploads/2018/01/RWeeklyXIV_Image.png?w=450&ssl=1" alt="" class="wp-image-11236" data-recalc-dims="1"></p>
<p>This week’s R bulletin covers some interesting ways to list functions, to list files and illustrates the use of double colon operator. </p>
<div></div>
<p>	<a rel="nofollow" href="https://twitter.com/share?text=Learn+some+interesting+R+programming+functions.+%40QuantInsti&url=https://www.quantinsti.com/blog/r-weekly-bulletin-vol-xiv/" data-link="https://twitter.com/share?text=Learn+some+interesting+R+programming+functions.+%40QuantInsti&amp;url=https://www.quantinsti.com/blog/r-weekly-bulletin-vol-xiv/" target="_blank"><span><span>We will also cover functions like path.package, fill.na, and rank. </span><span>Click To Tweet<i></i></span></span></a>Hope you like this R weekly bulletin. Enjoy reading!</p>
<p> </p>
<h3>Shortcut Keys</h3>
<p>1. New document – Ctrl+Shift+N<br>
2. Close active document – Ctrl+W<br>
3. Close all open documents – Ctrl+Shift+W</p>
<h3>Problem Solving Ideas</h3>
<h4>How to list functions from an R package</h4>
<p>We can view the functions from a particular R package by using the “jwutil”s package. Install the package and use the lsf function from the package. The syntax of the function is given as:</p>
<p>lsf(pkg)</p>
<p>Where pkg is a character string containing package name.</p>
<p>The function returns a character vector of function names in the given package.</p>
<p><strong>Example:</strong></p>
<pre>library(jwutil)
library(rowr)
lsf(&quot;rowr&quot;)</pre>
<p><img sizes="(max-width: 667px) 100vw, 667px" src="https://i1.wp.com/www.quantinsti.com/wp-content/uploads/2018/01/RWeekly-XIV.png?w=450&ssl=1" alt="" class="wp-image-11224" data-recalc-dims="1"></p>
<h4>How to list files with a particular extension</h4>
<p>To list files with a particular extension, one can use the pattern argument in the list.files function. For example to list CSV files use the following syntax:</p>
<p><strong>Example:</strong></p>
<pre># This will list all the csv files present in the current working directory.
# To list files in any other folder, you need to provide the folder path.

files = list.files(pattern = &quot;\\.csv$&quot;)

# $ at the end means that this is end of the string.
# Adding \. ensures that you match only files with extension .csv

list.files(path = &quot;C:/Users/MyFolder&quot;, pattern = &quot;\\.csv$&quot;)</pre>
<p><img sizes="(max-width: 663px) 100vw, 663px" src="https://i1.wp.com/www.quantinsti.com/wp-content/uploads/2018/01/RWeeklyXIV-2.png?w=450&ssl=1" alt="" class="wp-image-11226" data-recalc-dims="1"></p>
<h4>Using the double colon operator</h4>
<p>The double colon operator is used to access exported variables in a namespace. The syntax is given as:</p>
<p>pkg::name</p>
<p>Where pkg is the package name symbol or literal character string. The name argument is the variable name symbol or literal character string.</p>
<p>The expression pkg::name returns the value of the exported variable from the package if it has a namespace. The package will be loaded if it was not loaded already before the call. Using the double colon operator has its advantage when we have functions of the same name but from different packages. In such a case, the sequence in which the libraries are loaded is important.</p>
<p>To see the help documentation for these colon operators you can run the following command in R – ?’::’ or help(“:::”)</p>
<p><strong>Example:</strong></p>
<pre>library(&quot;dplyr&quot;)

first = c(1:6)
second = c(3:9)

dplyr::intersect(first, second)
[1] 3 4 5 6
base::intersect(first, second)
[1] 3 4 5 6</pre>
<p>In this example, we have two functions having the same names but from different R packages. In some cases, functions having same names can produce different results. By specifying the respective package name using the double colon operator, R knows in which package to look for the function.</p>
<h3>Functions Demystified</h3>
<h4>path.package function</h4>
<p>The path.package function returns path to the locations where the given package is found. If the package is not mentioned then the function will return the path of the all the currently attached packages. The syntax of the function is given as:</p>
<p>path.package(package, quiet = FALSE)</p>
<p>The quiet argument takes a default value of False. If this is changed to True then it will throw a warning if the package named in the argument is not attached and will give an error if none are attached.</p>
<p><strong>Example:</strong></p>
<pre>path.package(&quot;stats&quot;)</pre>
<p><img sizes="(max-width: 663px) 100vw, 663px" src="https://i1.wp.com/www.quantinsti.com/wp-content/uploads/2018/01/RWeeklyXIV-3.png?w=450&ssl=1" alt="" class="wp-image-11227" data-recalc-dims="1"></p>
<h4>fill.na function</h4>
<p>There are different R packages which have functions to fill NA values. The fill.na function is part of the mefa package and it replaces NA values with the nearest values above them in the same column.The syntax of the function is given as:</p>
<p>fill.na(x)</p>
<p>Where, x can be a vector, a matrix or a data frame.</p>
<p><strong>Example:</strong></p>
<pre>library(mefa)
x = c(12,NA,15,17,21,NA)
fill.na(x)</pre>
<p><img sizes="(max-width: 687px) 100vw, 687px" src="https://i0.wp.com/www.quantinsti.com/wp-content/uploads/2018/01/RWeeklyXIV-4.png?w=450&ssl=1" alt="" class="wp-image-11228" data-recalc-dims="1"></p>
<h4>rank function</h4>
<p>The rank function returns the sample ranks of the values in a vector. Ties (i.e., equal values) and missing values can be handled in several ways.</p>
<p>rank(x, na.last = TRUE, ties.method = c(“average”, “first”, “random”, “max”,”min”))</p>
<p>where,<br>
x: numeric, complex, character or logical vector<br>
na.last: for controlling the treatment of NAs. If TRUE, missing values in the data are put last; if FALSE, they are put first; if NA, they are removed; if “keep” they are kept with rank NA<br>
ties.method: a character string specifying how ties are treated</p>
<p><strong>Examples:</strong></p>
<pre>x = c(3, 5, 1, -4, NA, Inf, 90, 43)
rank(x)</pre>
<p><img sizes="(max-width: 705px) 100vw, 705px" src="https://i1.wp.com/www.quantinsti.com/wp-content/uploads/2018/01/RWeeklyXIV-5.png?w=450&ssl=1" alt="" class="wp-image-11229" data-recalc-dims="1"></p>
<pre>rank(x, na.last = FALSE)</pre>
<p><img sizes="(max-width: 696px) 100vw, 696px" src="https://i1.wp.com/www.quantinsti.com/wp-content/uploads/2018/01/RWeeklyXIV-6.png?w=450&ssl=1" alt="" class="wp-image-11230" data-recalc-dims="1"></p>
<h3>Next Step</h3>
<p>We hope you liked this bulletin. In the next weekly bulletin, we will list more interesting ways and methods plus R functions for our readers.</p>
<div><a rel="nofollow" href="https://www.quantinsti.com/wp-content/uploads/2018/01/QuantInsti_R_Bulletin-XIV.pdf" target="_blank">Download the PDF Now!</a></div>
<p>The post <a rel="nofollow" href="https://www.quantinsti.com/blog/r-weekly-bulletin-vol-xiv/" target="_blank">R Weekly Bulletin Vol – XIV</a> appeared first on <a rel="nofollow" href="https://www.quantinsti.com/" target="_blank"></a>.</p>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://www.quantinsti.com/blog/r-weekly-bulletin-vol-xiv/"> R programming</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/iQZpS9j9feY" height="1"></a></div>