<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Rense Nieuwenhuis &#187; open-source</title>
	<atom:link href="http://www.rensenieuwenhuis.nl/tag/open-source/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.rensenieuwenhuis.nl</link>
	<description>&#34;The extra-ordinary lies within the curve of normality&#34;</description>
	<lastBuildDate>Thu, 12 Mar 2026 14:58:15 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=4.2.2</generator>
	<item>
		<title>New version of WEC: focus on interactions</title>
		<link>http://www.rensenieuwenhuis.nl/new-version-of-wec-focus-on-interactions/</link>
		<comments>http://www.rensenieuwenhuis.nl/new-version-of-wec-focus-on-interactions/#comments</comments>
		<pubDate>Tue, 17 Jan 2017 11:00:52 +0000</pubDate>
		<dc:creator><![CDATA[Rense Nieuwenhuis]]></dc:creator>
				<category><![CDATA[My Publications]]></category>
		<category><![CDATA[R-Project]]></category>
		<category><![CDATA[Academic Software]]></category>
		<category><![CDATA[open-source]]></category>
		<category><![CDATA[R]]></category>
		<category><![CDATA[wec]]></category>
		<category><![CDATA[weighted effect coding]]></category>

		<guid isPermaLink="false">http://www.rensenieuwenhuis.nl/?p=6037</guid>
		<description><![CDATA[We have uploaded a new version of WEC, an R package to apply &#8216;weighted effect coding&#8217; to your dummy variables. With weighted effect coding, your dummy variables represent the deviation of their respective category from ...]]></description>
				<content:encoded><![CDATA[<p>We have uploaded a new version of WEC, an R package to apply &#8216;weighted effect coding&#8217; to your dummy variables. With weighted effect coding, your dummy variables represent the deviation of their respective category from the sample mean, rather than the deviation from a reference category. Particularly with observational data, which are often unbalanced, this can have attractive interpretations. We recently published two articles in which we discuss some of the advantages:</p>
<p><a href="http://doi.org/10.1007/s00038-016-0901-1"> Grotenhuis, M., Ben Pelzer, Eisinga, R., Nieuwenhuis, R., Schmidt-Catran, A., &#038; Konig, R. (2016b). When size matters: advantages of weighted effect coding in observational studies. <i>International Journal of Public Health</i>, 1–5. http://doi.org/10.1007/s00038-016-0901-1 </a></p>
<p><a href="http://doi.org/10.1007/s00038-016-0902-0"> Grotenhuis, M., Ben Pelzer, Eisinga, R., Nieuwenhuis, R., Schmidt-Catran, A., &#038; Konig, R. (2016a). A novel method for modelling interaction between categorical variables. <i>International Journal of Public Health</i>, 1–5. http://doi.org/10.1007/s00038-016-0902-0 </a></p>
<p>As some of the real advantages of  weighted effect coding come into play when using interactions, that was what we focused in the current update to our &#8216;wec&#8217; package (version 0.4). The package now supports interactions between a weighted effect coded factor variable and an interval variable, and the calculation of interactions between two weighted effect coded factor variables was much improved. An example is given below (with more to follow, hopefully soon).</p>
<p><code><br />
library(wec)<br />
data(PUMS)<br />
PUMS$race.wec <- factor(PUMS$race)<br />
contrasts(PUMS$race.wec) <- contr.wec(PUMS$race.wec, "White")<br />
PUMS$race.educint <- wec.interact(PUMS$race.wec, PUMS$education.int)<br />
m.wec.educ <- lm(wage ~ race.wec + education.int + race.educint, data=PUMS)<br />
summary(m.wec.educ)$coefficients<br />
</code></p>
<p>The code above results in a regression model (shown below) in which the main effect for education (9048) remains the same, whether the interaction terms are included or not (you can try this yourself). Thus, the interaction terms represent how much the average education effect varies by race.</p>
<pre>
                            Estimate Std. Error t value Pr(>|t|)
(Intercept)                     52320        559    93.5  0.0e+00
race.wecHispanic                -4955       1736    -2.9  4.3e-03
race.wecBlack                  -11276       1817    -6.2  5.7e-10
race.wecAsian                    5151       2381     2.2  3.1e-02
education.int                    9048        287    31.6 2.3e-208
race.educintinteractHispanic    -3266        977    -3.3  8.3e-04
race.educintinteractBlack       -3293        990    -3.3  8.8e-04
race.educintinteractAsian        3575       1217     2.9  3.3e-03
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.rensenieuwenhuis.nl/new-version-of-wec-focus-on-interactions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Update influence.ME, or why I love the open source community</title>
		<link>http://www.rensenieuwenhuis.nl/update-influence-me-or-why-i-love-the-open-source-community/</link>
		<comments>http://www.rensenieuwenhuis.nl/update-influence-me-or-why-i-love-the-open-source-community/#comments</comments>
		<pubDate>Wed, 17 Aug 2016 11:39:28 +0000</pubDate>
		<dc:creator><![CDATA[Rense Nieuwenhuis]]></dc:creator>
				<category><![CDATA[Blogging about Science]]></category>
		<category><![CDATA[Influence.ME]]></category>
		<category><![CDATA[R-Project]]></category>
		<category><![CDATA[Science]]></category>
		<category><![CDATA[influential cases]]></category>
		<category><![CDATA[mutlilevel]]></category>
		<category><![CDATA[open-source]]></category>
		<category><![CDATA[R]]></category>

		<guid isPermaLink="false">http://www.rensenieuwenhuis.nl/?p=5969</guid>
		<description><![CDATA[The other day, Kevin Darras contacted me about my R package influence.ME. The package didn’t work with the kind of models he wanted to estimate, and Kevin was looking for a solution. He had been ...]]></description>
				<content:encoded><![CDATA[<p>The other day, <a href="https://www.researchgate.net/profile/Kevin_Darras">Kevin Darras</a> contacted me about my R package influence.ME. The package didn’t work with the kind of models he wanted to estimate, and Kevin was looking for a solution. He had been able to go &#8216;under the hood’ of the program code in influence.ME and to program a solution, which he kindly shared with me. After some testing, and some adjustments, the influence.ME package is now updated and <a href="https://cran.r-project.org/web/packages/influence.ME/index.html">uploaded to CRAN</a>, available for anyone to use. That’s well within a week after his first e-mail.</p>
<p>This is why I love the open source community so much. Not only can users extend the use of influence.ME, and all other R packages, to do things that the package authors/maintainers did not implement. Or to check procedures. Or fix mistakes. Moreover, in line with the positive attitude towards sharing in the open access community, the improved code was shared back so that other users can benefit.</p>
<p>So, thanks to the help of the community, I am happy to announce an update to influence.ME, with two improvements:</p>
<ul>
<li>influence.ME now better handles binomial models</li>
<li>influence.ME now supports functions inside the model call;for instance:<br />
model.a <- lmer(math ~ structure + scale(SES)  + (1 | school.ID), data=school23)
</li>
</ul>
<p>influence.ME is an extension package for the R statistical software. It provides tools for detecting influential data in multilevel regression models (also known as mixed effects models). It was introduced in the R Journal (Nieuwenhuis, Te Grotenhuis &#038; Pelzer, 2012). influence.ME can be downloaded from with the R software.</p>
<p>Nieuwenhuis, R., Grotenhuis, te, H. F., &#038; Pelzer, B. J. (2012). <a href="https://journal.r-project.org/archive/2012-2/RJournal_2012-2_Nieuwenhuis~et~al.pdf">Influence. ME: tools for detecting influential data in mixed effects models</a>. R Journal, 4(2), 38–47.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rensenieuwenhuis.nl/update-influence-me-or-why-i-love-the-open-source-community/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>R-Sessions 11: Tables</title>
		<link>http://www.rensenieuwenhuis.nl/r-sessions-11-tables/</link>
		<comments>http://www.rensenieuwenhuis.nl/r-sessions-11-tables/#comments</comments>
		<pubDate>Fri, 15 Aug 2008 10:00:27 +0000</pubDate>
		<dc:creator><![CDATA[Rense Nieuwenhuis]]></dc:creator>
				<category><![CDATA[R-Project]]></category>
		<category><![CDATA[R-Sessions]]></category>
		<category><![CDATA[Academic Software]]></category>
		<category><![CDATA[open-source]]></category>
		<category><![CDATA[Statistics]]></category>
		<category><![CDATA[tables]]></category>

		<guid isPermaLink="false">http://www.rensenieuwenhuis.nl/?p=425</guid>
		<description><![CDATA[The one most often used function in the analysis of statistical data is the creation of tables. This edition of the R-Sessions describes the use of several functions to do some nifty cross-tabulations. And more.]]></description>
				<content:encoded><![CDATA[<p><a href="http://www.rensenieuwenhuis.nl/archive/category/r-project/r-sessions/"><img src="http://i1.wp.com/www.rensenieuwenhuis.nl/wp-content/uploads/2008/07/r-sessions.jpg?w=470" " title="R-Sessions" data-recalc-dims="1" /></a></p>
<p><!--adsense--><br />
The one most often used function in the analysis of statistical data is the creation of tables. This edition of the R-Sessions describes the use of several functions to do some nifty cross-tabulations. And more.</p>
<h2>TAPPLY</h2>
<p>The function TAPPLY can be used to perform calculations on table-marginals. Different functions can be used, such as MEAN, SUM, VAR, SD, LENGTH (for frequency-tables). For example: <span id="more-425"></span></p>
<blockquote><p> x &lt;- c(0,1,2,3,4,5,6,7,8,9)<br />
y &lt;- c(1,1,1,1,1,1,2,2,2,2)<br />
tapply(x,y,mean)<br />
tapply(x,y,sum)<br />
tapply(x,y,var)<br />
tapply(x,y,length)</p></blockquote>
<pre>
&gt; x &lt;- c(0,1,2,3,4,5,6,7,8,9)
&gt; y &lt;- c(1,1,1,1,1,1,2,2,2,2)
&gt; tapply(x,y,mean)
  1     2
2.5   7.5
&gt; tapply(x,y,sum)
 1  2
15 30
&gt; tapply(x,y,var)
       1        2
3.500000 1.666667
&gt; tapply(x,y,length)
1 2
6 4
&gt;</pre>
<h2>FTABLE</h2>
<p>More elaborate frequency tables can be created with the FTABLE-function. For example:</p>
<blockquote><p> x &lt;- c(0,1,2,3,4,5,6,7,8,9)<br />
y &lt;- c(1,1,1,1,1,1,2,2,2,2)<br />
z &lt;- c(1,1,1,2,2,2,2,2,1,1)<br />
ftable(x,y,z)</p></blockquote>
<pre>
&gt; x &lt;- c(0,1,2,3,4,5,6,7,8,9)
&gt; y &lt;- c(1,1,1,1,1,1,2,2,2,2)
&gt; z &lt;- c(1,1,1,2,2,2,2,2,1,1)
&gt; ftable(x,y,z)
    z 1 2
x y
0 1   1 0
  2   0 0
1 1   1 0
  2   0 0
2 1   1 0
  2   0 0
3 1   0 1
  2   0 0
4 1   0 1
  2   0 0
5 1   0 1
  2   0 0
6 1   0 0
  2   0 1
7 1   0 0
  2   0 1
8 1   0 0
  2   1 0
9 1   0 0
  2   1 0</pre>
<p><i><br />
&#8211; &#8211; &#8212; &#8212; &#8212;&#8211; &#8212;&#8212;&#8211;</p>
<ul>
<li><b><a href="http://www.rensenieuwenhuis.nl/R-forum/">Discuss this article and pose additional questions in the R-Sessions Forum</a></b></li>
<li><b><a href="http://www.rensenieuwenhuis.nl/r-project/manual/basics/tables/">Find the original article embedded in the manual.</a></b></li>
</ul>
<p>&#8211; &#8211; &#8212; &#8212; &#8212;&#8211; &#8212;&#8212;&#8211;<br />
<a href="http://www.rensenieuwenhuis.nl/archive/category/r-project/r-sessions/">R-Sessions</a> is a collection of manual chapters for R-Project, which are maintained on <a href="www.rensenieuwenhuis.nl">Curving Normality</a>. All posts are linked to the chapters from the R-Project manual on this site. The manual is free to use, for it is paid by the advertisements, but please refer to it in your work inspired by it. Feedback and topic requests are highly appreciated.<br />
&#8212;&#8212;&#8211; &#8212;&#8211; &#8212; &#8212; &#8211; &#8211;<br />
</i></p>
]]></content:encoded>
			<wfw:commentRss>http://www.rensenieuwenhuis.nl/r-sessions-11-tables/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>R-Sessions 10: Conditionals</title>
		<link>http://www.rensenieuwenhuis.nl/r-sessions-10-conditionals/</link>
		<comments>http://www.rensenieuwenhuis.nl/r-sessions-10-conditionals/#comments</comments>
		<pubDate>Wed, 13 Aug 2008 10:00:21 +0000</pubDate>
		<dc:creator><![CDATA[Rense Nieuwenhuis]]></dc:creator>
				<category><![CDATA[R-Project]]></category>
		<category><![CDATA[R-Sessions]]></category>
		<category><![CDATA[Academic Software]]></category>
		<category><![CDATA[open-source]]></category>
		<category><![CDATA[Statistics]]></category>

		<guid isPermaLink="false">http://www.rensenieuwenhuis.nl/?p=423</guid>
		<description><![CDATA[Conditionals, or logicals, are used to check vectors of data against conditions. In practice, this is used to select subsets of data or to recode values. In this edition of the R-Sessions, some of the fundamentals of conditionals are described.]]></description>
				<content:encoded><![CDATA[<p><a href="http://www.rensenieuwenhuis.nl/archive/category/r-project/r-sessions/"><img src="http://i2.wp.com/www.rensenieuwenhuis.nl/wp-content/uploads/2008/07/r-sessions.jpg?w=470" " title="R-Sessions" data-recalc-dims="1" /></a></p>
<p><!--adsense--> Conditionals, or logicals, are used to check vectors of data against conditions. In practice, this is used to select subsets of data or to recode values. Here, only some of the fundamentals of conditionals are described.</p>
<h2>Basics</h2>
<p>The general form of conditionals are two values, or two sets of values, and the condition to test against. Examples of such tests are &#8216;is larger than&#8217;, &#8216;equals&#8217;, and &#8216;is larger than&#8217;. In the example below the values &#8216;3&#8217; and &#8216;4&#8217; are tested using these three tests.</p>
<blockquote><p> 3 &gt; 4 3 == 4 3 &lt; 4</p></blockquote>
<p><span id="more-423"></span></p>
<pre>
&gt; 3 &gt; 4
[1] FALSE
&gt; 3 == 4
[1] FALSE
&gt; 3 &lt; 4
[1] TRUE</pre>
<h2>Numerical returns</h2>
<p>The output shown directly above makes clear that R-Project returns the values &#8216;TRUE&#8217; and &#8216;FALSE&#8217; to conditional tests. The results here are pretty straightforward: 3 is not larger than 4, therefore R returns FALSE. If you don&#8217;t desire TRUE or FALSE as response, but a numeric output, use the as.numeric() command which transforms the values to numerics, in this case &#8216;0&#8217; or &#8216;1&#8217;. This is shown below.</p>
<blockquote><p> as.numeric(3 &gt; 4) as.numeric(3 &lt; 4)</p></blockquote>
<pre>
&gt; as.numeric(3 &gt; 4)
[1] 0
&gt; as.numeric(3 &lt; 4)
[1] 1</pre>
<h2>Conditionals on vectors</h2>
<p>As on most functionality of R-project, vectors (or multiple values) can be used alongside single values, as is the case on conditionals. These can be used not only against single values, but against variables containing multiple values as well. This will result in a succession of tests, one for each value in the variable. The output is a vector of values, &#8216;TRUE&#8217; or &#8216;FALSE&#8217;.The examples below show two things: the subsequent values 1 to 10 are tested against the condition &#8216;is smaller than or equals 5&#8242;. It is shown as well that when these values are assigned to a variable (here: &#8216;x&#8217;), this variable can be tested against the same condition, giving exactly the same results.</p>
<blockquote><p> 1:10 1:10 &lt;= 5 x &lt;- 1:10 x &lt;= 5</p></blockquote>
<pre>
&gt; 1:10
 [1]  1  2  3  4  5  6  7  8  9 10
&gt; 1:10 &lt;= 5
 [1]  TRUE  TRUE  TRUE  TRUE  TRUE FALSE FALSE FALSE FALSE FALSE
&gt; x &lt;- 1:10
&gt; x == 5
 [1]  TRUE  TRUE  TRUE  TRUE  TRUE FALSE FALSE FALSE FALSE FALSE</pre>
<h2>Conditionals and multiple tests</h2>
<p>More tests can be gathered into one conditional expression. For instance, building on the example above, the first row of the next example tests the values of variable &#8216;x&#8217; against being smaller than or equal to 4, <em>or</em> being larger than or equal to &#8216;6&#8217;. This results in &#8216;TRUE&#8217; for all the values, except for 5. Since the &#8216;|&#8217;-operator is used, only one of the set conditions need to be true. The second row of this example below tests the same values against two conditions as well, namely &#8216;equal to or larger than 4&#8242; and &#8216;equal to or smaller than 6&#8242;. since this time the &#8216;&amp;&#8217;-operator is used, both conditionals need to be true.</p>
<blockquote><p> x &lt;= 4 | x &gt;= 6 x &gt;= 4 &amp; x &lt;= 6</p></blockquote>
<pre>
&gt; x &lt;= 4 | x &gt;= 6
 [1]  TRUE  TRUE  TRUE  TRUE FALSE  TRUE  TRUE  TRUE  TRUE  TRUE
&gt; x &gt;= 4 &amp; x &lt;= 6
 [1] FALSE FALSE FALSE  TRUE  TRUE  TRUE FALSE FALSE FALSE FALSE</pre>
<h2>Conditionals on character values</h2>
<p>In the example below, a string variable &#8216;gender&#8217; is constructed, containing the values &#8216;male&#8217; and &#8216;female&#8217;.  This is shown in the first two rows of the example below.</p>
<blockquote><p> gender &lt;- c(&#8220;male&#8221;,&#8221;female&#8221;,&#8221;female&#8221;,&#8221;male&#8221;,&#8221;male&#8221;,&#8221;male&#8221;,&#8221;female&#8221;) gender == &#8220;male&#8221;</p></blockquote>
<pre>
&gt; gender &lt;- c("male","female","female","male","male","male","female")
&gt; gender == "male"
[1]  TRUE FALSE FALSE  TRUE  TRUE  TRUE FALSE</pre>
<h2>Additional functions</h2>
<p>The last examples demonstrate two other functions using conditionals, using the same &#8216;gender&#8217; variable as above. The first is an additional way to get a numerical output of the same test as in the row above. The iselse() command has three arguments: the first is a conditional, the second is the desired output if the conditional is TRUE, the third is the output in case the result of the test is &#8216;FALSE&#8217;. The second example shows a way to obtain a list of which values match the condition tested against. In the output above, the second, third and last values are &#8216;female&#8217;. Using which() and the condition &#8220;== &#8216;male&#8217; &#8221; (equals &#8216;male&#8217;) returns the indices of the values in variable &#8216;gender&#8217; that equal &#8216;male&#8217;.</p>
<blockquote><p> ifelse(gender==&#8221;male&#8221;,0,1) which(gender==&#8221;male&#8221;)</p></blockquote>
<pre>
&gt; ifelse(gender=="male",0,1)
[1] 0 1 1 0 0 0 1
&gt; which(gender=="male")
[1] 1 4 5 6</pre>
<h2>Conditionals on missing values</h2>
<p>Missings values (&#8216;NA&#8217;) form a special case in many ways, such as when using conditionals. Normal conditionals cannot be used to find the missing values in a range of values, as is shown below.</p>
<blockquote><p> x &lt;- c(4,3,6,NA,4,3,NA) x == NA which(x == NA)  is.na(x) which(is.na(x))</p></blockquote>
<p>The last two rows of the syntax above show what can be done. The is.na() command tests whether a value or a vector of values is missing. It returns a vector of logicals (&#8216;TRUE&#8217; or &#8216;FALSE&#8217;), that indicates missing values with a &#8216;TRUE&#8217;. Nesting this command in the which() command described earlier enables us to find which of the values are missing. In this case, the fourth and the seventh values are missing.</p>
<pre>
&gt; x &lt;- c(4,3,6,NA,4,3,NA)
&gt; x == NA
[1] NA NA NA NA NA NA NA
&gt; which(x == NA)
integer(0)
&gt; is.na(x)
[1] FALSE FALSE FALSE  TRUE FALSE FALSE  TRUE
&gt; which(is.na(x))
[1] 4 7</pre>
<p><i><br />
&#8211; &#8211; &#8212; &#8212; &#8212;&#8211; &#8212;&#8212;&#8211;</p>
<ul>
<li><b><a href="http://www.rensenieuwenhuis.nl/r-forum/topic/r-sessions-10-conditionals">Discuss this article and pose additional questions in the R-Sessions Forum</a></b></li>
<li><b><a href="http://www.rensenieuwenhuis.nl/r-project/manual/basics/conditionals/">Find the original article embedded in the manual.</a></b></li>
</ul>
<p>&#8211; &#8211; &#8212; &#8212; &#8212;&#8211; &#8212;&#8212;&#8211;<br />
<a href="http://www.rensenieuwenhuis.nl/archive/category/r-project/r-sessions/">R-Sessions</a> is a collection of manual chapters for R-Project, which are maintained on <a href="www.rensenieuwenhuis.nl">Curving Normality</a>. All posts are linked to the chapters from the R-Project manual on this site. The manual is free to use, for it is paid by the advertisements, but please refer to it in your work inspired by it. Feedback and topic requests are highly appreciated.<br />
&#8212;&#8212;&#8211; &#8212;&#8211; &#8212; &#8212; &#8211; &#8211;<br />
</i></p>
]]></content:encoded>
			<wfw:commentRss>http://www.rensenieuwenhuis.nl/r-sessions-10-conditionals/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>R-Sessions 09: Data Manipulation</title>
		<link>http://www.rensenieuwenhuis.nl/r-sessions-09-data-manipulation/</link>
		<comments>http://www.rensenieuwenhuis.nl/r-sessions-09-data-manipulation/#comments</comments>
		<pubDate>Mon, 11 Aug 2008 10:00:39 +0000</pubDate>
		<dc:creator><![CDATA[Rense Nieuwenhuis]]></dc:creator>
				<category><![CDATA[R-Project]]></category>
		<category><![CDATA[R-Sessions]]></category>
		<category><![CDATA[Academic Software]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[data-manipulation]]></category>
		<category><![CDATA[open-source]]></category>
		<category><![CDATA[Statistics]]></category>

		<guid isPermaLink="false">http://www.rensenieuwenhuis.nl/?p=421</guid>
		<description><![CDATA[Today's edition of R-Sessions deals with the manipulation of data that is stored R-Project. Building upon the previous R-Session, attention is paid to recoding of data, ordering, and finally the merging of several sets of data.]]></description>
				<content:encoded><![CDATA[<p><a href="http://www.rensenieuwenhuis.nl/archive/category/r-project/r-sessions/"><img src="http://i0.wp.com/www.rensenieuwenhuis.nl/wp-content/uploads/2008/07/r-sessions.jpg?w=470" " title="R-Sessions" data-recalc-dims="1" /></a><br />
<!--adsense--></p>
<p>Today&#8217;s edition of R-Sessions deals with the manipulation of data that is stored R-Project. Building upon the previous R-Session, attention is paid to recoding of data, ordering, and finally the merging of several sets of data.</p>
<p><span id="more-421"></span></p>
<h2>Recoding</h2>
<p>The most direct way to recode data in R-Project is using a combination of both indexing and <a href="http://www.rensenieuwenhuis.nl/r-project/manual/basics/conditionals/">conditionals as described elsewhere</a>. To exemplify this, a simply data.frame will be created below, containing variables indicating gender and monthly income in thousands of euros.</p>
<blockquote><p> gender &lt;- c(&#8220;male&#8221;, &#8220;female&#8221;, &#8220;female&#8221;, &#8220;male&#8221;, &#8220;male&#8221;, &#8220;male&#8221;, &#8220;female&#8221;)<br />
income &lt;- c(54, 34, 556, 57, 88, 856, 23)<br />
data &lt;- data.frame(gender, income)<br />
data</p></blockquote>
<pre>
&gt; gender &lt;- c("male", "female", "female", "male", "male", "male", "female")
&gt; income &lt;- c(54, 34, 556, 57, 88, 856, 23)
&gt; data &lt;- data.frame(gender, income)
&gt; data
  gender income
1   male     54
2 female     34
3 female    556
4   male     57
5   male     88
6   male    856
7 female     23</pre>
<p>Some of the values on the income variable seem exceptionally high. Let&#8217;s say we want to remove the two values on income higher than 500. In order to do so, we use the which() command, that reveals which of the values is greater than 500. Next, the result of this is used for indexing the data$income variable. Finally, the indicator for missing values, &#8216;NA&#8217; is assigned to the that selected values of the &#8216;income&#8217; variables. Obviously, we would normally only use the third line. The first two are shown here, to make clear exactly what is happening.</p>
<blockquote><p> which(data$income &gt; 500)<br />
data$income[data$income &gt; 500]<br />
data$income[data$income &gt; 500] &lt;- NA<br />
data</p></blockquote>
<pre>
&gt; which(data$income &gt; 500)
[1] 3 6
&gt; data$income[data$income &gt; 500]
[1] 556 856
&gt; data$income[data$income &gt; 500] &lt;- NA
&gt; data
  gender income
1   male     54
2 female     34
3 female     NA
4   male     57
5   male     88
6   male     NA
7 female     23</pre>
<p>Sometimes, it is desirable to replace missing values by the mean on the respective variables. That is what we are going to do here. Note, that in general practice it is not very sensible to impute two missing values using only five valid values. Nevertheless, we will proceed here.<br />
The first row of the example below shows that it is not automatically possible to calculate the mean of a variable that contains missing values. Since R-Project cannot compute a valid value, NA is returned. This is not what we want. Therefore, we instruct R-Project to remove missing values by adding na.rm=TRUE to the mean() command. Now, the right value is returned. When the same selection-techniques as above are used, an error will occur. Therefore, we need the is.na() command, that returns a vector of logicals (&#8216;TRUE&#8217; and &#8216;FALSE&#8217; ). Using is.na(), we can use the which() command to select the desired values on the income variable. To these, the calculated mean is assigned.</p>
<blockquote><p> mean(data$income)<br />
mean(data$income, na.rm=TRUE)<br />
data$income[which(is.na(data$income))] &lt;- mean(data$income, na.rm=TRUE)<br />
data</p></blockquote>
<pre>
&gt; mean(data$income)
[1] NA
&gt; mean(data$income, na.rm=TRUE)
[1] 51.2
&gt; data$income[which(is.na(data$income))] &lt;- mean(data$income, na.rm=TRUE)
&gt; data
  gender income
1   male   54.0
2 female   34.0
3 female   51.2
4   male   57.0
5   male   88.0
6   male   51.2
7 female   23.0</pre>
<h2>ORDER</h2>
<p>It is easy to sort a data-frame using the command order. Combined with indexing functions, it works as follows:</p>
<pre>
x &lt;- c(1,3,5,4,2)
y &lt;- c('a','b','c','d','e')
df &lt;- data.frame(x,y)

df
  x y
1 1 a
2 3 b
3 5 c
4 4 d
5 2 e

df[order(df$x),]
  x y
1 1 a
5 2 e
2 3 b
4 4 d
3 5 c</pre>
<h2>MERGE</h2>
<p>Merge puts multiple data.frames together, based on an identifier-variable which is unique or a combination of variables.</p>
<pre>
x &lt;- c(1,2,5,4,3)
y &lt;- c(1,2,3,4,5)
z &lt;- c('a','b','c','d','e')

df1 &lt;- data.frame(x,y)
df2 &lt;- data.frame(x,z)
df3 &lt;- merge(df1,df2,by=c("x"))

 df3
  x y z
1 1 1 a
2 2 2 b
3 3 5 e
4 4 4 d
5 5 3 c</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.rensenieuwenhuis.nl/r-sessions-09-data-manipulation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>R-Sessions 05: Getting Help</title>
		<link>http://www.rensenieuwenhuis.nl/r-sessions-05-getting-help/</link>
		<comments>http://www.rensenieuwenhuis.nl/r-sessions-05-getting-help/#comments</comments>
		<pubDate>Fri, 01 Aug 2008 10:00:14 +0000</pubDate>
		<dc:creator><![CDATA[Rense Nieuwenhuis]]></dc:creator>
				<category><![CDATA[R-Project]]></category>
		<category><![CDATA[R-Sessions]]></category>
		<category><![CDATA[Academic Software]]></category>
		<category><![CDATA[help]]></category>
		<category><![CDATA[open-source]]></category>

		<guid isPermaLink="false">http://www.rensenieuwenhuis.nl/?p=413</guid>
		<description><![CDATA[Concordant with the open source community, R-Project is accompanied by many additional help functions. Most of them are freely available.]]></description>
				<content:encoded><![CDATA[<p><a href="http://www.rensenieuwenhuis.nl/archive/category/r-project/r-sessions/"><img src="http://i2.wp.com/www.rensenieuwenhuis.nl/wp-content/uploads/2008/07/r-sessions.jpg?w=470" " title="R-Sessions" data-recalc-dims="1" /></a></p>
<p><!--adsense--><br />
Concordant with the open source community, R-Project is accompanied by many additional help functions. Most of them are freely available.</p>
<h2>The help() &#8211; function</h2>
<p>R-Project has a help function build in. This functionality is focused on informing the user on the parameters function have. Almost for all functions some examples are given as well.</p>
<p>A general help page is available, which contains several introductory documents as &#8216;An Introduction to R&#8217;, &#8216;Frequently Asked Questions&#8217;, and &#8216;The R Language Definition&#8217;. More advanced documents are made available as well, such as &#8216;Writing R Extensions&#8217; and &#8216;R Internals&#8217;. This general help page is called for by entering:</p>
<blockquote><p> help.start()</p></blockquote>
<p>To obtain help on a specific function, you use help() with the name of the function between the brackets. For instance, if you want help on the plot() function, use the following syntax:</p>
<blockquote><p> help(plot)</p></blockquote>
<p>This results in a page that gives a short definition of the function, shows the parameters of the function, links to related functions, and finally gives some examples.</p>
<h2>Freely available documents</h2>
<p>More elaborate documents can be found on the website of R-Project (http://www.r-project.org) in the documents section. This can be found by clicking on &#8216;manuals&#8217; from the home-page, just below the &#8216;documents&#8217; header. First, a couple of documents written by the core development team of R-Project are offered, but don&#8217;t forget to click on the &#8216;Contributed Documentation&#8217; link, which leads to many more documents, often of a very high quality.</p>
<h2>Books on R-Project</h2>
<p>Many books have been written on R-Project, ranging from very basic-level introductions to the ones that address the fundamental parts of the software. In this manual I review some of these books, which I can advise to every starting or more advanced user of R-Project:</p>
<ul>
<li>Mixed-Effect Models in S and S-Plus, by JosÃ© Pinheiro &amp; Douglas Bates</li>
<li>An R and S-PLUS Companion to Applied Regression, by John Fox</li>
<li>Introductory Statistics with R, by Peter Dalgaard</li>
<li>Data Analysis Using Regression and Multilevel / Hierarchical Models, by Andrew Gelman and Jennifer Hill</li>
</ul>
<h2>R-help mailinglist</h2>
<p>When all help fails, there is always the R-Help mailing-list. This is a service where all members receive the e-mails that are send to a specific address. The quality and speed of the given answers and solutions is often very high. Questions are asked and answered many times a day, so be prepared to receive a high volume of e-mail when signing up for this service.</p>
<p>More information on the R-help mailing-list, as well as the ability to sign-up, can be found on: https://stat.ethz.ch/mailman/listinfo/r-help</p>
<p><span id="more-413"></span></p>
<p><i><br />
&#8211; &#8211; &#8212; &#8212; &#8212;&#8211; &#8212;&#8212;&#8211;</p>
<ul>
<li><b><a href="http://www.rensenieuwenhuis.nl/r-forum/topic/r-sessions-05-getting-help">Discuss this article and pose additional questions in the R-Sessions Forum</a></b></li>
<li><b><a href="http://www.rensenieuwenhuis.nl/r-project/manual/introduction/getting-help/">Find the original article embedded in the manual.</a></b></li>
</ul>
<p>&#8211; &#8211; &#8212; &#8212; &#8212;&#8211; &#8212;&#8212;&#8211;<br />
<a href="http://www.rensenieuwenhuis.nl/archive/category/r-project/r-sessions/">R-Sessions</a> is a collection of manual chapters for R-Project, which are maintained on <a href="www.rensenieuwenhuis.nl">Curving Normality</a>. All posts are linked to the chapters from the R-Project manual on this site. The manual is free to use, for it is paid by the advertisements, but please refer to it in your work inspired by it. Feedback and topic requests are highly appreciated.<br />
&#8212;&#8212;&#8211; &#8212;&#8211; &#8212; &#8212; &#8211; &#8211;<br />
</i></p>
]]></content:encoded>
			<wfw:commentRss>http://www.rensenieuwenhuis.nl/r-sessions-05-getting-help/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
