<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: Design Flaws in R #3 — Zero Subscripts</title>
	<atom:link href="http://radfordneal.wordpress.com/2008/09/21/design-flaws-in-r-3-%e2%80%94-zero-subscripts/feed/" rel="self" type="application/rss+xml" />
	<link>http://radfordneal.wordpress.com/2008/09/21/design-flaws-in-r-3-%e2%80%94-zero-subscripts/</link>
	<description></description>
	<lastBuildDate>Sat, 03 Oct 2009 22:21:37 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Radford Neal</title>
		<link>http://radfordneal.wordpress.com/2008/09/21/design-flaws-in-r-3-%e2%80%94-zero-subscripts/#comment-192</link>
		<dc:creator>Radford Neal</dc:creator>
		<pubDate>Tue, 11 Nov 2008 19:56:05 +0000</pubDate>
		<guid isPermaLink="false">http://radfordneal.wordpress.com/?p=503#comment-192</guid>
		<description>I agree that it&#039;s not clear that an error should always be signalled when using NA in a subscript to &lt;i&gt;access&lt;/i&gt; elements.  I say above only that it should be an error when &lt;i&gt;replacing&lt;/i&gt; elements. 

However, I&#039;m not convinced that the example you give is good behaviour.  If I use a vector of TRUE/FALSE values as a subscript, I expect to get a vector whose length is equal to the number of TRUE values.  If some of these TRUE/FALSE values are actually NA, the length of vector to return is uncertain (if you think of NA as being unceretainly either TRUE or FALSE).  This is not at all the same as a vector of a well-defined length in which some elements are NA.  In particular, it&#039;s unlikely that the presence of the NA elements will correctly propagate through subsequent operations to produce a sensible result. So it may be best to signal an error when a logical vector containing an NA is used as a subscript.

The situation is different when the subscript is a vector of integers, some of which are NA.  Then the result should be a vector the same length as the subscript, and putting in NA where the subscript is NA correctly represents the uncertainty in the value of that subscript.

It&#039;s interesting that %in% handles NA the way you show, though I&#039;m not sure it&#039;s consistent with R&#039;s general treatment of NA!</description>
		<content:encoded><![CDATA[<p>I agree that it&#8217;s not clear that an error should always be signalled when using NA in a subscript to <i>access</i> elements.  I say above only that it should be an error when <i>replacing</i> elements. </p>
<p>However, I&#8217;m not convinced that the example you give is good behaviour.  If I use a vector of TRUE/FALSE values as a subscript, I expect to get a vector whose length is equal to the number of TRUE values.  If some of these TRUE/FALSE values are actually NA, the length of vector to return is uncertain (if you think of NA as being unceretainly either TRUE or FALSE).  This is not at all the same as a vector of a well-defined length in which some elements are NA.  In particular, it&#8217;s unlikely that the presence of the NA elements will correctly propagate through subsequent operations to produce a sensible result. So it may be best to signal an error when a logical vector containing an NA is used as a subscript.</p>
<p>The situation is different when the subscript is a vector of integers, some of which are NA.  Then the result should be a vector the same length as the subscript, and putting in NA where the subscript is NA correctly represents the uncertainty in the value of that subscript.</p>
<p>It&#8217;s interesting that %in% handles NA the way you show, though I&#8217;m not sure it&#8217;s consistent with R&#8217;s general treatment of NA!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kenn Konstabel</title>
		<link>http://radfordneal.wordpress.com/2008/09/21/design-flaws-in-r-3-%e2%80%94-zero-subscripts/#comment-191</link>
		<dc:creator>Kenn Konstabel</dc:creator>
		<pubDate>Tue, 11 Nov 2008 10:13:24 +0000</pubDate>
		<guid isPermaLink="false">http://radfordneal.wordpress.com/?p=503#comment-191</guid>
		<description>I agree that many of the flaws referred to above are indeed flaws. But R&#039;s behavior in subsetting a vector with NA&#039;s makes perfect sense:

a&lt;-c(NA,3)
a[a==3]
# the first element might well be 3, were it not missing!!!!
# but if you want just 3&#039;s, no NA&#039;s:
# and it&#039;s not about subsetting, it&#039;s about comparing with `==`

a[a %in% 3]

#or
b &lt;- na.omit(a)
b[b==3]

# or even [very funny!!!]
a[sapply(a, identical, 3)]

I almost always use %in% instead of == in functions</description>
		<content:encoded><![CDATA[<p>I agree that many of the flaws referred to above are indeed flaws. But R&#8217;s behavior in subsetting a vector with NA&#8217;s makes perfect sense:</p>
<p>a&lt;-c(NA,3)<br />
a[a==3]<br />
# the first element might well be 3, were it not missing!!!!<br />
# but if you want just 3&#8217;s, no NA&#8217;s:<br />
# and it&#8217;s not about subsetting, it&#8217;s about comparing with `==`</p>
<p>a[a %in% 3]</p>
<p>#or<br />
b &lt;- na.omit(a)<br />
b[b==3]</p>
<p># or even [very funny!!!]<br />
a[sapply(a, identical, 3)]</p>
<p>I almost always use %in% instead of == in functions</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Radford Neal</title>
		<link>http://radfordneal.wordpress.com/2008/09/21/design-flaws-in-r-3-%e2%80%94-zero-subscripts/#comment-171</link>
		<dc:creator>Radford Neal</dc:creator>
		<pubDate>Mon, 29 Sep 2008 13:28:48 +0000</pubDate>
		<guid isPermaLink="false">http://radfordneal.wordpress.com/?p=503#comment-171</guid>
		<description>Using = rather than &lt;- does avoid the formatting problems.

The effect of 4 versus -4 does seem a bit funny, though individually the definitions of what they do seem reasonably sensible (not necessarily the best way, since many buggy references will be considered valid, but not silly).

Many properties that one might hope for aren&#039;t going to be satisfied by R&#039;s indexing.  For instance, one might hope that saving the i&#039;th element in another variable, then setting it to something else, then setting it back to its saved value, would leave the vector unchanged.  But of course it won&#039;t if the index is beyond the previous extent of the vector.</description>
		<content:encoded><![CDATA[<p>Using = rather than &lt;- does avoid the formatting problems.</p>
<p>The effect of 4 versus -4 does seem a bit funny, though individually the definitions of what they do seem reasonably sensible (not necessarily the best way, since many buggy references will be considered valid, but not silly).</p>
<p>Many properties that one might hope for aren&#8217;t going to be satisfied by R&#8217;s indexing.  For instance, one might hope that saving the i&#8217;th element in another variable, then setting it to something else, then setting it back to its saved value, would leave the vector unchanged.  But of course it won&#8217;t if the index is beyond the previous extent of the vector.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sandro Saitta</title>
		<link>http://radfordneal.wordpress.com/2008/09/21/design-flaws-in-r-3-%e2%80%94-zero-subscripts/#comment-170</link>
		<dc:creator>Sandro Saitta</dc:creator>
		<pubDate>Mon, 29 Sep 2008 07:26:46 +0000</pubDate>
		<guid isPermaLink="false">http://radfordneal.wordpress.com/?p=503#comment-170</guid>
		<description>&gt; a = c(1,2,3)
&gt; a[4]
[1] NA
&gt; a[-4]
[1] 1 2 3</description>
		<content:encoded><![CDATA[<p>&gt; a = c(1,2,3)<br />
&gt; a[4]<br />
[1] NA<br />
&gt; a[-4]<br />
[1] 1 2 3</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David MacKay</title>
		<link>http://radfordneal.wordpress.com/2008/09/21/design-flaws-in-r-3-%e2%80%94-zero-subscripts/#comment-167</link>
		<dc:creator>David MacKay</dc:creator>
		<pubDate>Fri, 26 Sep 2008 01:04:05 +0000</pubDate>
		<guid isPermaLink="false">http://radfordneal.wordpress.com/?p=503#comment-167</guid>
		<description>&gt; a[HA]
[1] HA HA HA HA HA

 I&#039;m reminded of the useful conversational elements in the English-Spanish phrase book.
Do you speak Norwegian?
 ...
Does anyone here speak Norwegian?
 ...
I don&#039;t speak Norwegian.</description>
		<content:encoded><![CDATA[<p>&gt; a[HA]<br />
[1] HA HA HA HA HA</p>
<p> I&#8217;m reminded of the useful conversational elements in the English-Spanish phrase book.<br />
Do you speak Norwegian?<br />
 &#8230;<br />
Does anyone here speak Norwegian?<br />
 &#8230;<br />
I don&#8217;t speak Norwegian.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Radford Neal</title>
		<link>http://radfordneal.wordpress.com/2008/09/21/design-flaws-in-r-3-%e2%80%94-zero-subscripts/#comment-166</link>
		<dc:creator>Radford Neal</dc:creator>
		<pubDate>Thu, 25 Sep 2008 19:48:02 +0000</pubDate>
		<guid isPermaLink="false">http://radfordneal.wordpress.com/?p=503#comment-166</guid>
		<description>I think something got absorbed by the blog software in the above post.  I that that to enter a less-than sign, you need to use ampersand, &quot;l&quot;, &quot;t&quot;, semicolon.  I&#039;ll try it here: &lt;

Unfortunately, there seems to be no way to edit comments after they&#039;re submitted, even for me when moderating them.</description>
		<content:encoded><![CDATA[<p>I think something got absorbed by the blog software in the above post.  I that that to enter a less-than sign, you need to use ampersand, &#8220;l&#8221;, &#8220;t&#8221;, semicolon.  I&#8217;ll try it here: &lt;</p>
<p>Unfortunately, there seems to be no way to edit comments after they&#8217;re submitted, even for me when moderating them.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sandro Saitta</title>
		<link>http://radfordneal.wordpress.com/2008/09/21/design-flaws-in-r-3-%e2%80%94-zero-subscripts/#comment-165</link>
		<dc:creator>Sandro Saitta</dc:creator>
		<pubDate>Thu, 25 Sep 2008 19:42:42 +0000</pubDate>
		<guid isPermaLink="false">http://radfordneal.wordpress.com/?p=503#comment-165</guid>
		<description>Again, very good point. In fact I find indexes not straightforward in R since you can have negative indexes (to remove an element). So I find this somehow dangerous:

&lt;code&gt;
&gt; a  a[4]
[1] NA
&gt; a[-4]
[1] 1 2 3
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>Again, very good point. In fact I find indexes not straightforward in R since you can have negative indexes (to remove an element). So I find this somehow dangerous:</p>
<p><code><br />
&gt; a  a[4]<br />
[1] NA<br />
&gt; a[-4]<br />
[1] 1 2 3<br />
</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aniko Szabo</title>
		<link>http://radfordneal.wordpress.com/2008/09/21/design-flaws-in-r-3-%e2%80%94-zero-subscripts/#comment-164</link>
		<dc:creator>Aniko Szabo</dc:creator>
		<pubDate>Mon, 22 Sep 2008 15:07:22 +0000</pubDate>
		<guid isPermaLink="false">http://radfordneal.wordpress.com/?p=503#comment-164</guid>
		<description>I apparently did not enter the first code-block right:
It should be:
a &lt;- c(NA,1:3)
a[a==3]

Is there a way to preview submissions?</description>
		<content:encoded><![CDATA[<p>I apparently did not enter the first code-block right:<br />
It should be:<br />
a &lt;- c(NA,1:3)<br />
a[a==3]</p>
<p>Is there a way to preview submissions?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aniko Szabo</title>
		<link>http://radfordneal.wordpress.com/2008/09/21/design-flaws-in-r-3-%e2%80%94-zero-subscripts/#comment-163</link>
		<dc:creator>Aniko Szabo</dc:creator>
		<pubDate>Mon, 22 Sep 2008 15:05:54 +0000</pubDate>
		<guid isPermaLink="false">http://radfordneal.wordpress.com/?p=503#comment-163</guid>
		<description>Those are some cool &quot;features&quot;. The last one apparently happens because NA is logical while NA+0 is numeric.
My favorite related annoyance is with subsetting with NAs:
&lt;code&gt;
&gt; a  a[a==3]
[1] NA  3
&lt;/code&gt;
I can see the logic, but it catches me all the time. The simplest solution that I know is to use
&lt;code&gt;
&gt; a[which(a==3)]
[1] 3
&lt;/code&gt;
but I still don&#039;t like the default.
This is just to support your statement that it is not clear what to do with subsetting with NAs.</description>
		<content:encoded><![CDATA[<p>Those are some cool &#8220;features&#8221;. The last one apparently happens because NA is logical while NA+0 is numeric.<br />
My favorite related annoyance is with subsetting with NAs:<br />
<code><br />
&gt; a  a[a==3]<br />
[1] NA  3<br />
</code><br />
I can see the logic, but it catches me all the time. The simplest solution that I know is to use<br />
<code><br />
&gt; a[which(a==3)]<br />
[1] 3<br />
</code><br />
but I still don&#8217;t like the default.<br />
This is just to support your statement that it is not clear what to do with subsetting with NAs.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Antonio Di Narzo</title>
		<link>http://radfordneal.wordpress.com/2008/09/21/design-flaws-in-r-3-%e2%80%94-zero-subscripts/#comment-162</link>
		<dc:creator>Antonio Di Narzo</dc:creator>
		<pubDate>Mon, 22 Sep 2008 13:47:56 +0000</pubDate>
		<guid isPermaLink="false">http://radfordneal.wordpress.com/?p=503#comment-162</guid>
		<description>A very good point indeed.
Maybe a way to address it while maintaining the R engine backward compatible is to raise a warning when 0s in indexing.
If one desires, by setting
&gt; options(warn=2)
the interpreter will stop on warnings, giving a safer computational framework. What do you think about that?</description>
		<content:encoded><![CDATA[<p>A very good point indeed.<br />
Maybe a way to address it while maintaining the R engine backward compatible is to raise a warning when 0s in indexing.<br />
If one desires, by setting<br />
&gt; options(warn=2)<br />
the interpreter will stop on warnings, giving a safer computational framework. What do you think about that?</p>
]]></content:encoded>
	</item>
</channel>
</rss>
