<?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:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: Design Flaws in R #2 — Dropped Dimensions</title>
	<atom:link href="http://radfordneal.wordpress.com/2008/08/20/design-flaws-in-r-2-%E2%80%94-dropped-dimensions/feed/" rel="self" type="application/rss+xml" />
	<link>http://radfordneal.wordpress.com/2008/08/20/design-flaws-in-r-2-%e2%80%94-dropped-dimensions/</link>
	<description></description>
	<lastBuildDate>Mon, 10 Jun 2013 16:04:09 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: Anonymous</title>
		<link>http://radfordneal.wordpress.com/2008/08/20/design-flaws-in-r-2-%e2%80%94-dropped-dimensions/#comment-940</link>
		<dc:creator><![CDATA[Anonymous]]></dc:creator>
		<pubDate>Thu, 02 May 2013 20:17:06 +0000</pubDate>
		<guid isPermaLink="false">http://radfordneal.wordpress.com/?p=302#comment-940</guid>
		<description><![CDATA[Thank you, this is a very useful tip! I have an automated porgram that has to deal with this situation often. The &quot;drop&quot; statement shortened my program by at least 20 lines!]]></description>
		<content:encoded><![CDATA[<p>Thank you, this is a very useful tip! I have an automated porgram that has to deal with this situation often. The &#8220;drop&#8221; statement shortened my program by at least 20 lines!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Clement Kent</title>
		<link>http://radfordneal.wordpress.com/2008/08/20/design-flaws-in-r-2-%e2%80%94-dropped-dimensions/#comment-932</link>
		<dc:creator><![CDATA[Clement Kent]]></dc:creator>
		<pubDate>Wed, 06 Mar 2013 23:06:17 +0000</pubDate>
		<guid isPermaLink="false">http://radfordneal.wordpress.com/?p=302#comment-932</guid>
		<description><![CDATA[My previous comment on APL, the predecessor of R and S, applies well to Eli&#039;s complaint. APL, and a number of non-S languages that descend from it, do not drop dimensions, have rational designs for permutation, transposition, and subsetting, and allow a larger number of operations along dimensions of arrays than R. I&#039;m not going backward to use APL, but really wish R could be upgraded to be as good as its grandparent is for arrays.]]></description>
		<content:encoded><![CDATA[<p>My previous comment on APL, the predecessor of R and S, applies well to Eli&#8217;s complaint. APL, and a number of non-S languages that descend from it, do not drop dimensions, have rational designs for permutation, transposition, and subsetting, and allow a larger number of operations along dimensions of arrays than R. I&#8217;m not going backward to use APL, but really wish R could be upgraded to be as good as its grandparent is for arrays.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Radford Neal</title>
		<link>http://radfordneal.wordpress.com/2008/08/20/design-flaws-in-r-2-%e2%80%94-dropped-dimensions/#comment-931</link>
		<dc:creator><![CDATA[Radford Neal]]></dc:creator>
		<pubDate>Wed, 06 Mar 2013 20:29:41 +0000</pubDate>
		<guid isPermaLink="false">http://radfordneal.wordpress.com/?p=302#comment-931</guid>
		<description><![CDATA[For the three-dimensional case, you maybe should use the &quot;aperm&quot; function.]]></description>
		<content:encoded><![CDATA[<p>For the three-dimensional case, you maybe should use the &#8220;aperm&#8221; function.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eli</title>
		<link>http://radfordneal.wordpress.com/2008/08/20/design-flaws-in-r-2-%e2%80%94-dropped-dimensions/#comment-930</link>
		<dc:creator><![CDATA[Eli]]></dc:creator>
		<pubDate>Wed, 06 Mar 2013 20:13:34 +0000</pubDate>
		<guid isPermaLink="false">http://radfordneal.wordpress.com/?p=302#comment-930</guid>
		<description><![CDATA[I too write a lot of programs in R that use matrix multiplication.

#this is an example that kills me
a=matrix(1,4,4)
# transpose of the first row is a 4x1 COLUMN matrix
t(a[1,])

sadly, first R removes the dim attr, then does a transpose on the vector (which by some bizarre logic is possible with no dim attr) and gives you a 1x4 ROW matrix. 

Horrible.  However this is easily circumvented by employing drop=FALSE defensively throughout all your R code.  Until... you need to work with arrays with more than 2 dimensions. 

a=array(1,dim=c(1,2,10))
#once again R drops the dim attr and we get a row
t(a[,,1])
#that&#039;s ok, let&#039;s use drop=FALSE
t(a[,,1,drop=FALSE])
#oh no, a is not a matrix so we get an error
#--which actually makes sense unlike the behavior for t() on a vector with no dim attr

But what do we do to get a[,,1] as a matrix so we can take the transpose?

#this works but is computationally 3x as expensive as needed
b=a[,,1]
dim(b)=c(dim(a)[1],dim(a)[2])
t(b)

#this is less expensive but ugly
matrix(a[,,1],dim(a)[2],dim(a)[1],byrow=TRUE)

#by the way, this does not work for getting the correct transpose of a matrix
b=a[,,1]
dim(b)=c(dim(a)[2],dim(a)[1])

My solution was to write my own utility function for subsetting 3D matrices.]]></description>
		<content:encoded><![CDATA[<p>I too write a lot of programs in R that use matrix multiplication.</p>
<p>#this is an example that kills me<br />
a=matrix(1,4,4)<br />
# transpose of the first row is a 4&#215;1 COLUMN matrix<br />
t(a[1,])</p>
<p>sadly, first R removes the dim attr, then does a transpose on the vector (which by some bizarre logic is possible with no dim attr) and gives you a 1&#215;4 ROW matrix. </p>
<p>Horrible.  However this is easily circumvented by employing drop=FALSE defensively throughout all your R code.  Until&#8230; you need to work with arrays with more than 2 dimensions. </p>
<p>a=array(1,dim=c(1,2,10))<br />
#once again R drops the dim attr and we get a row<br />
t(a[,,1])<br />
#that&#8217;s ok, let&#8217;s use drop=FALSE<br />
t(a[,,1,drop=FALSE])<br />
#oh no, a is not a matrix so we get an error<br />
#&#8211;which actually makes sense unlike the behavior for t() on a vector with no dim attr</p>
<p>But what do we do to get a[,,1] as a matrix so we can take the transpose?</p>
<p>#this works but is computationally 3x as expensive as needed<br />
b=a[,,1]<br />
dim(b)=c(dim(a)[1],dim(a)[2])<br />
t(b)</p>
<p>#this is less expensive but ugly<br />
matrix(a[,,1],dim(a)[2],dim(a)[1],byrow=TRUE)</p>
<p>#by the way, this does not work for getting the correct transpose of a matrix<br />
b=a[,,1]<br />
dim(b)=c(dim(a)[2],dim(a)[1])</p>
<p>My solution was to write my own utility function for subsetting 3D matrices.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Radford Neal</title>
		<link>http://radfordneal.wordpress.com/2008/08/20/design-flaws-in-r-2-%e2%80%94-dropped-dimensions/#comment-835</link>
		<dc:creator><![CDATA[Radford Neal]]></dc:creator>
		<pubDate>Wed, 24 Oct 2012 22:24:22 +0000</pubDate>
		<guid isPermaLink="false">http://radfordneal.wordpress.com/?p=302#comment-835</guid>
		<description><![CDATA[Well, S and APL both have vectors, but beyond that, any connection is VERY loose...]]></description>
		<content:encoded><![CDATA[<p>Well, S and APL both have vectors, but beyond that, any connection is VERY loose&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Clement Kent</title>
		<link>http://radfordneal.wordpress.com/2008/08/20/design-flaws-in-r-2-%e2%80%94-dropped-dimensions/#comment-834</link>
		<dc:creator><![CDATA[Clement Kent]]></dc:creator>
		<pubDate>Wed, 24 Oct 2012 21:41:30 +0000</pubDate>
		<guid isPermaLink="false">http://radfordneal.wordpress.com/?p=302#comment-834</guid>
		<description><![CDATA[A bit of history: S was loosely based on the much more rigorous language APL. APL is  more consistent about dimensions than either S or R and is/was, IMHO, easier to use for most array manipulations. On the other hand, R is free and comes with a gazillion great packages; APL is now used by a much smaller group of programmers than R.]]></description>
		<content:encoded><![CDATA[<p>A bit of history: S was loosely based on the much more rigorous language APL. APL is  more consistent about dimensions than either S or R and is/was, IMHO, easier to use for most array manipulations. On the other hand, R is free and comes with a gazillion great packages; APL is now used by a much smaller group of programmers than R.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Radford Neal</title>
		<link>http://radfordneal.wordpress.com/2008/08/20/design-flaws-in-r-2-%e2%80%94-dropped-dimensions/#comment-652</link>
		<dc:creator><![CDATA[Radford Neal]]></dc:creator>
		<pubDate>Tue, 06 Dec 2011 19:41:49 +0000</pubDate>
		<guid isPermaLink="false">http://radfordneal.wordpress.com/?p=302#comment-652</guid>
		<description><![CDATA[Yes, but matrix(M[1:i,],ncol=ncol(M),byrow=TRUE) is even worse than M[1:i,,drop=FALSE].]]></description>
		<content:encoded><![CDATA[<p>Yes, but matrix(M[1:i,],ncol=ncol(M),byrow=TRUE) is even worse than M[1:i,,drop=FALSE].</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: denes turei</title>
		<link>http://radfordneal.wordpress.com/2008/08/20/design-flaws-in-r-2-%e2%80%94-dropped-dimensions/#comment-651</link>
		<dc:creator><![CDATA[denes turei]]></dc:creator>
		<pubDate>Tue, 06 Dec 2011 01:23:07 +0000</pubDate>
		<guid isPermaLink="false">http://radfordneal.wordpress.com/?p=302#comment-651</guid>
		<description><![CDATA[or you can use a function 
as.matrix()
or 
matrix(vector,ncol=a,byrow=T)]]></description>
		<content:encoded><![CDATA[<p>or you can use a function<br />
as.matrix()<br />
or<br />
matrix(vector,ncol=a,byrow=T)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Florian B</title>
		<link>http://radfordneal.wordpress.com/2008/08/20/design-flaws-in-r-2-%e2%80%94-dropped-dimensions/#comment-286</link>
		<dc:creator><![CDATA[Florian B]]></dc:creator>
		<pubDate>Thu, 12 Aug 2010 16:12:47 +0000</pubDate>
		<guid isPermaLink="false">http://radfordneal.wordpress.com/?p=302#comment-286</guid>
		<description><![CDATA[Regarding the disambiguation of vectors versus matrixes:

 A matrix is just a vector with a dim attribute:
&gt; v  v
 [1]  1  2  3  4  5  6  7  8  9 10
&gt; attr(v,&quot;dim&quot;)  v
     [,1] [,2] [,3] [,4] [,5]
[1,]    1    3    5    7    9
[2,]    2    4    6    8   10

There are loads of things in R which are confusing in the beginning, but once you know them, often you can work with them.]]></description>
		<content:encoded><![CDATA[<p>Regarding the disambiguation of vectors versus matrixes:</p>
<p> A matrix is just a vector with a dim attribute:<br />
&gt; v  v<br />
 [1]  1  2  3  4  5  6  7  8  9 10<br />
&gt; attr(v,&#8221;dim&#8221;)  v<br />
     [,1] [,2] [,3] [,4] [,5]<br />
[1,]    1    3    5    7    9<br />
[2,]    2    4    6    8   10</p>
<p>There are loads of things in R which are confusing in the beginning, but once you know them, often you can work with them.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Radford Neal</title>
		<link>http://radfordneal.wordpress.com/2008/08/20/design-flaws-in-r-2-%e2%80%94-dropped-dimensions/#comment-259</link>
		<dc:creator><![CDATA[Radford Neal]]></dc:creator>
		<pubDate>Fri, 13 Nov 2009 00:31:18 +0000</pubDate>
		<guid isPermaLink="false">http://radfordneal.wordpress.com/?p=302#comment-259</guid>
		<description><![CDATA[I think &quot;data analysis&quot; versus &quot;programming&quot; is a false distinction.  A data analysis environment that doesn&#039;t allow programming would be very limiting.  That&#039;s one reason why R is popular - you can use it for data analysis, which includes a bit of programming now and then when you need to (for example) do some complicated conversion from one data format to another.

I also think that there is little or no actual conflict between good features for data analysis and good features for programming.  Historically, S was designed first with data analysis in mind, with probably little thought for programming.  And I&#039;m not blaming the original designers for not forseeing how programming would become more important.  But if S/R were re-designed from scratch, there would be no reason to put in features bad for programming in order to make data analysis easier.  It&#039;s not too hard to make things good for both.  Even now, it may not be hard, as seen from my other posts on how to solve these problems.]]></description>
		<content:encoded><![CDATA[<p>I think &#8220;data analysis&#8221; versus &#8220;programming&#8221; is a false distinction.  A data analysis environment that doesn&#8217;t allow programming would be very limiting.  That&#8217;s one reason why R is popular &#8211; you can use it for data analysis, which includes a bit of programming now and then when you need to (for example) do some complicated conversion from one data format to another.</p>
<p>I also think that there is little or no actual conflict between good features for data analysis and good features for programming.  Historically, S was designed first with data analysis in mind, with probably little thought for programming.  And I&#8217;m not blaming the original designers for not forseeing how programming would become more important.  But if S/R were re-designed from scratch, there would be no reason to put in features bad for programming in order to make data analysis easier.  It&#8217;s not too hard to make things good for both.  Even now, it may not be hard, as seen from my other posts on how to solve these problems.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
