<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"> <channel><title>2657 Productions News</title> <link>http://news.mrdwab.com</link> <description>..:: Whereabouts and Whatabouts of the 2657 World ::..</description> <lastBuildDate>Tue, 04 Dec 2012 07:52:48 +0000</lastBuildDate> <language>en-US</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.5.1</generator> <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/2657Productions" /><feedburner:info uri="2657productions" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license><image><link>http://creativecommons.org/licenses/by-nc-sa/3.0/</link><url>http://creativecommons.org/images/public/somerights20.gif</url><title>Some Rights Reserved</title></image><feedburner:emailServiceId>2657Productions</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><item><title>What exactly is “elegant” code in R?</title><link>http://feedproxy.google.com/~r/2657Productions/~3/yZUndn8U7ec/</link> <comments>http://news.mrdwab.com/2012/12/04/what-exactly-is-elegant-code-in-r/#comments</comments> <pubDate>Tue, 04 Dec 2012 07:52:48 +0000</pubDate> <dc:creator>Ananda Mahto</dc:creator> <category><![CDATA[Geekiness]]></category> <category><![CDATA[Useless Knowledge]]></category> <category><![CDATA[elegant code]]></category> <category><![CDATA[R]]></category> <category><![CDATA[Stack Overflow]]></category> <guid isPermaLink="false">http://news.mrdwab.com/?p=1259</guid> <description><![CDATA[In celebration of my achieving 10,000 &#8220;reputation&#8221; on Stack Overflow, I&#8217;m re-posting one of my questions from there that was (as I had expected) deleted after being live for about 5 hours. In that time, I never really got a &#8230; <a
href="http://news.mrdwab.com/2012/12/04/what-exactly-is-elegant-code-in-r/">Continue reading <span
class="meta-nav">&#8594;</span></a>]]></description> <content:encoded><![CDATA[<p>In celebration of my achieving 10,000 &#8220;reputation&#8221; on <a
href="http://stackoverflow.com/users/1270695/ananda-mahto">Stack Overflow</a>, I&#8217;m re-posting one of my questions from there that was (as I had expected) deleted after being live for about 5 hours. In that time, I never really got a satisfactory answer, so if anyone wants to offer one in the comments, that would be great!</p><p><span
id="more-1259"></span></p><p>Here is the post:</p><hr
/><p>I almost exclusively follow the R tag&#8211;it&#8217;s my current &#8220;playground&#8221;&#8211;and I have been noticing <em>many</em> questions phrased along the way of &#8220;what is an <strong><em>elegant</em></strong> way to do XYZ&#8221; or answers in the form of &#8220;this may not be the most <strong><em>elegant</em></strong> solution, but it does what you want.&#8221; (I know <em>many</em> is subjective, but search the R tag for elegant, and you will find at least one question every other day or so with the word in it.)</p><p>My &#8220;question&#8221; is, what exactly is <em>elegant</em> code?</p><p>Is it:</p><ul><li>Code that is easily readable?</li><li>Code that does everything in one line (I see a lot of congratulations for these so-called &#8220;one-liners&#8221;)?</li><li>Code that is faster?</li><li>Something totally different?</li></ul><p>I&#8217;ve seen in some documents (for example <a
href="http://cran.r-project.org/doc/contrib/Genolini-S4tutorialV0-5en.pdf"><em>A (Not So) Short Introduction to S4</em>, Section 1.6</a>) what I feel are much more understandable terms for describing code: good, clean, bad, dangerous, dirty&#8230;.  As I write this, <a
href="http://stackoverflow.com/users/602276/andrie">@Andrie</a> is schooling (politely&#8211;&#8221;Summer of Love&#8221; fashion) a new user on how to &#8220;<a
href="http://stackoverflow.com/a/11878172/1270695"><em>clean</em> your code and make life easier in the long term</a>&#8221; (emphasis added).  And, what comes to mind when I try to write code are things like consistency, readability, efficiency, not producing unexpected output, not breaking other functions. These descriptions for code seem to fit with such terms, but not necessarily with what I would call <em>elegant</em>.</p><p>I&#8217;m also often confused when an answerer posts what I consider an excellent answer, perhaps incrementally building towards the desired output, but modestly states it is not <em>elegant</em>.  If the answer does exactly what is expected to do, isn&#8217;t that the whole point of the code?</p><h2>Some further background</h2><p>My initial questions regarding this started when I read a line in a question by <a
href="http://stackoverflow.com/users/636656/ari-b-friedman">@AriB.Friedman</a> about <a
href="http://stackoverflow.com/q/10055602/1270695">making base R reshape easier to use</a> that read:</p><blockquote><blockquote><p>It is a truth universally acknowledged that R&#8217;s base reshape command is speedy and powerful but has miserable syntax.</p></blockquote></blockquote><p>The word <em>elegant</em> was not used here, but this is an example of where I might use it. Ari was trying to make an incredibly useful function easier to use by making the user input more consistent, much like some of <a
href="http://stackoverflow.com/users/16632/hadley">Hadley Wickham</a>&#8216;s packages are wrappers around base R functions, often combining common steps that a user might go through. The result of these new functions is not always more <em>efficient</em>, but the code that is written is often more easy to decipher, and thus provide what I might call a more <em>elegant</em> approach.</p><blockquote><blockquote><p>(Note: I fully <em>expect</em> that this question would be closed as &#8220;off topic&#8221;, &#8220;not a real question&#8221;, or &#8220;not constructive&#8221;, since it is not <em>directly</em> programming related; but while it stays open, hopefully there are some helpful answers.)</p></blockquote></blockquote> <div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/2657Productions?a=yZUndn8U7ec:GzXpuj0iLXI:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/2657Productions?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/2657Productions?a=yZUndn8U7ec:GzXpuj0iLXI:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/2657Productions?i=yZUndn8U7ec:GzXpuj0iLXI:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/2657Productions?a=yZUndn8U7ec:GzXpuj0iLXI:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/2657Productions?i=yZUndn8U7ec:GzXpuj0iLXI:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/2657Productions?a=yZUndn8U7ec:GzXpuj0iLXI:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/2657Productions?d=TzevzKxY174" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/2657Productions?a=yZUndn8U7ec:GzXpuj0iLXI:bAAVSKdHlY4"><img src="http://feeds.feedburner.com/~ff/2657Productions?i=yZUndn8U7ec:GzXpuj0iLXI:bAAVSKdHlY4" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/2657Productions/~4/yZUndn8U7ec" height="1" width="1"/>]]></content:encoded> <wfw:commentRss>http://news.mrdwab.com/2012/12/04/what-exactly-is-elegant-code-in-r/feed/</wfw:commentRss> <slash:comments>1</slash:comments> <feedburner:origLink>http://news.mrdwab.com/2012/12/04/what-exactly-is-elegant-code-in-r/</feedburner:origLink></item> <item><title>I’m not at all religious, but…</title><link>http://feedproxy.google.com/~r/2657Productions/~3/rPmhmOn7Inw/</link> <comments>http://news.mrdwab.com/2011/06/26/im-not-at-all-religious-but/#comments</comments> <pubDate>Sun, 26 Jun 2011 12:43:03 +0000</pubDate> <dc:creator>Ananda</dc:creator> <category><![CDATA[(all categories)]]></category> <category><![CDATA[Humor]]></category> <category><![CDATA[Pictures]]></category> <category><![CDATA[Ambika!]]></category> <category><![CDATA[silly pictures]]></category> <guid isPermaLink="false">http://news.mrdwab.com/?p=1199</guid> <description><![CDATA[&#8230; here is a goddess that I am happy to worship&#8230; I also had a few alternatives&#8211;and I&#8217;m still not sure which one is my favorite.]]></description> <content:encoded><![CDATA[<p>&#8230; here is a goddess that I am happy to worship&#8230;</p><div
id="attachment_1200" class="wp-caption aligncenter" style="width: 410px"><a
href="http://news.mrdwab.com/2011/06/26/im-not-at-all-religious-but/ambika-border-1/" rel="attachment wp-att-1200"><img
src="http://i1.wp.com/news.mrdwab.com/wp-content/uploads/2011/06/Ambika-Border-1.jpg?resize=400%2C400" alt="" title="Ambika - Border 1" class="size-medium wp-image-1200" data-recalc-dims="1" /></a><p
class="wp-caption-text">Don&#039;t make me squirt my milk bottle at you!</p></div><p><span
id="more-1199"></span></p><p>I also had a few alternatives&#8211;and I&#8217;m still not sure which one is my favorite.</p> <a
href='http://news.mrdwab.com/2011/06/26/im-not-at-all-religious-but/ambika-border-1/' title='Don&#039;t make me squirt my milk bottle at you!'><img
data-attachment-id="1200" data-orig-file="http://i1.wp.com/news.mrdwab.com/wp-content/uploads/2011/06/Ambika-Border-1.jpg?resize=1600%2C1600" data-orig-size="1600,1600" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}" data-image-title="Don&#8217;t make me squirt my milk bottle at you!" data-image-description="" data-medium-file="http://i1.wp.com/news.mrdwab.com/wp-content/uploads/2011/06/Ambika-Border-1.jpg?fit=400%2C400" data-large-file="http://i1.wp.com/news.mrdwab.com/wp-content/uploads/2011/06/Ambika-Border-1.jpg?fit=1024%2C1024" src="http://i1.wp.com/news.mrdwab.com/wp-content/uploads/2011/06/Ambika-Border-1.jpg?resize=150%2C150" class="attachment-thumbnail" alt="Don&#039;t make me squirt my milk bottle at you!" /></a> <a
href='http://news.mrdwab.com/2011/06/26/im-not-at-all-religious-but/ambika-border-sepia/' title='One of the ancient goddesses...'><img
data-attachment-id="1203" data-orig-file="http://i2.wp.com/news.mrdwab.com/wp-content/uploads/2011/06/Ambika-Border-Sepia.jpg?resize=1678%2C1668" data-orig-size="1678,1668" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}" data-image-title="One of the ancient goddesses&#8230;" data-image-description="" data-medium-file="http://i2.wp.com/news.mrdwab.com/wp-content/uploads/2011/06/Ambika-Border-Sepia.jpg?fit=400%2C400" data-large-file="http://i2.wp.com/news.mrdwab.com/wp-content/uploads/2011/06/Ambika-Border-Sepia.jpg?fit=1024%2C1024" src="http://i2.wp.com/news.mrdwab.com/wp-content/uploads/2011/06/Ambika-Border-Sepia.jpg?resize=150%2C150" class="attachment-thumbnail" alt="One of the ancient goddesses..." /></a> <a
href='http://news.mrdwab.com/2011/06/26/im-not-at-all-religious-but/ambika-colored-pencil/' title='In a coloring book coming to a bookstore near you!'><img
data-attachment-id="1204" data-orig-file="http://i0.wp.com/news.mrdwab.com/wp-content/uploads/2011/06/Ambika-Colored-Pencil.jpg?resize=1600%2C1600" data-orig-size="1600,1600" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}" data-image-title="In a coloring book coming to a bookstore near you!" data-image-description="" data-medium-file="http://i0.wp.com/news.mrdwab.com/wp-content/uploads/2011/06/Ambika-Colored-Pencil.jpg?fit=400%2C400" data-large-file="http://i0.wp.com/news.mrdwab.com/wp-content/uploads/2011/06/Ambika-Colored-Pencil.jpg?fit=1024%2C1024" src="http://i0.wp.com/news.mrdwab.com/wp-content/uploads/2011/06/Ambika-Colored-Pencil.jpg?resize=150%2C150" class="attachment-thumbnail" alt="In a coloring book coming to a bookstore near you!" /></a> <a
href='http://news.mrdwab.com/2011/06/26/im-not-at-all-religious-but/ambika-third-eye/' title='The third eye begins to glow just before Kali begins to emerge from Ambika.'><img
data-attachment-id="1205" data-orig-file="http://i2.wp.com/news.mrdwab.com/wp-content/uploads/2011/06/Ambika-Third-Eye.jpg?resize=1716%2C1716" data-orig-size="1716,1716" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}" data-image-title="The third eye begins to glow just before Kali begins to emerge from Ambika." data-image-description="" data-medium-file="http://i2.wp.com/news.mrdwab.com/wp-content/uploads/2011/06/Ambika-Third-Eye.jpg?fit=400%2C400" data-large-file="http://i2.wp.com/news.mrdwab.com/wp-content/uploads/2011/06/Ambika-Third-Eye.jpg?fit=1024%2C1024" src="http://i2.wp.com/news.mrdwab.com/wp-content/uploads/2011/06/Ambika-Third-Eye.jpg?resize=150%2C150" class="attachment-thumbnail" alt="The third eye begins to glow just before Kali begins to emerge from Ambika." /></a> <a
href='http://news.mrdwab.com/2011/06/26/im-not-at-all-religious-but/ambika/' title='The original....'><img
data-attachment-id="1206" data-orig-file="http://i0.wp.com/news.mrdwab.com/wp-content/uploads/2011/06/Ambika.jpg?resize=1600%2C1600" data-orig-size="1600,1600" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}" data-image-title="The original&#8230;." data-image-description="" data-medium-file="http://i0.wp.com/news.mrdwab.com/wp-content/uploads/2011/06/Ambika.jpg?fit=400%2C400" data-large-file="http://i0.wp.com/news.mrdwab.com/wp-content/uploads/2011/06/Ambika.jpg?fit=1024%2C1024" src="http://i0.wp.com/news.mrdwab.com/wp-content/uploads/2011/06/Ambika.jpg?resize=150%2C150" class="attachment-thumbnail" alt="The original...." /></a> <div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/2657Productions?a=rPmhmOn7Inw:NfPdMzLyAZc:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/2657Productions?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/2657Productions?a=rPmhmOn7Inw:NfPdMzLyAZc:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/2657Productions?i=rPmhmOn7Inw:NfPdMzLyAZc:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/2657Productions?a=rPmhmOn7Inw:NfPdMzLyAZc:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/2657Productions?i=rPmhmOn7Inw:NfPdMzLyAZc:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/2657Productions?a=rPmhmOn7Inw:NfPdMzLyAZc:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/2657Productions?d=TzevzKxY174" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/2657Productions?a=rPmhmOn7Inw:NfPdMzLyAZc:bAAVSKdHlY4"><img src="http://feeds.feedburner.com/~ff/2657Productions?i=rPmhmOn7Inw:NfPdMzLyAZc:bAAVSKdHlY4" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/2657Productions/~4/rPmhmOn7Inw" height="1" width="1"/>]]></content:encoded> <wfw:commentRss>http://news.mrdwab.com/2011/06/26/im-not-at-all-religious-but/feed/</wfw:commentRss> <slash:comments>0</slash:comments> <feedburner:origLink>http://news.mrdwab.com/2011/06/26/im-not-at-all-religious-but/</feedburner:origLink></item> <item><title>On the trucks around town…</title><link>http://feedproxy.google.com/~r/2657Productions/~3/MrtfNBylC5c/</link> <comments>http://news.mrdwab.com/2011/06/15/on-the-trucks-around-town/#comments</comments> <pubDate>Wed, 15 Jun 2011 04:40:22 +0000</pubDate> <dc:creator>Ananda</dc:creator> <category><![CDATA[(all categories)]]></category> <category><![CDATA[(non) fiction]]></category> <category><![CDATA[Humor]]></category> <category><![CDATA[India]]></category> <category><![CDATA[Pictures]]></category> <category><![CDATA[Ambika!]]></category> <category><![CDATA[silly pictures]]></category> <category><![CDATA[we two ours one]]></category> <guid isPermaLink="false">http://news.mrdwab.com/?p=1189</guid> <description><![CDATA[Anyone who has spent some time in India is sure to have noticed the slogans painted on the back of trucks, autos, and other vehicles advising &#8220;we two, ours one&#8221;. This is part of India&#8217;s &#8220;family planning&#8221; efforts&#8211;efforts which have &#8230; <a
href="http://news.mrdwab.com/2011/06/15/on-the-trucks-around-town/">Continue reading <span
class="meta-nav">&#8594;</span></a>]]></description> <content:encoded><![CDATA[<p>Anyone who has spent some time in India is sure to have noticed the slogans painted on the back of trucks, autos, and other vehicles advising &#8220;we two, ours one&#8221;. This is part of India&#8217;s &#8220;<a
href="http://en.wikipedia.org/wiki/Human_population_control#India">family planning</a>&#8221; efforts&#8211;efforts which have had a pretty <a
href="http://en.wikipedia.org/wiki/Family_planning_in_India">bumpy history</a> that included a forced sterilization program.</p><p>Originally, the slogans were &#8220;we two, ours two&#8221;, or at least that was the catchy English version&#8211;regional languages usually had a slogan more along the lines of &#8220;one family, two children&#8221;. And, the change to the new slogan led to at least one humorous math discussion with an auto driver who commented that, &#8220;Earlier, it was &#8216;we two, ours two&#8217;; now, it is &#8216;we two, ours one&#8217;. What&#8217;s next? &#8216;We two, ours half?&#8217;&#8221;</p><p>Anyway, keen observers might have noticed the following new addition to selected trucks:</p><p><a
href="http://news.mrdwab.com/2011/06/15/on-the-trucks-around-town/we-2-ours-1-1/" rel="attachment wp-att-1190"><img
src="http://i1.wp.com/news.mrdwab.com/wp-content/uploads/2011/06/We-2-Ours-1-1.jpg?resize=400%2C300" alt="We two, ours one" title="We 2 Ours 1-1" class="aligncenter size-medium wp-image-1190" data-recalc-dims="1" /></a></p><p><a
href="http://news.mrdwab.com/2011/06/15/on-the-trucks-around-town/we-2-ours-1-2/" rel="attachment wp-att-1193"><img
src="http://i0.wp.com/news.mrdwab.com/wp-content/uploads/2011/06/We-2-Ours-1-2.jpg?resize=400%2C270" alt="We two, ours one" title="We 2 Ours 1-2" class="aligncenter size-medium wp-image-1193" data-recalc-dims="1" /></a></p> <div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/2657Productions?a=MrtfNBylC5c:kpdUUVZsD3Y:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/2657Productions?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/2657Productions?a=MrtfNBylC5c:kpdUUVZsD3Y:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/2657Productions?i=MrtfNBylC5c:kpdUUVZsD3Y:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/2657Productions?a=MrtfNBylC5c:kpdUUVZsD3Y:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/2657Productions?i=MrtfNBylC5c:kpdUUVZsD3Y:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/2657Productions?a=MrtfNBylC5c:kpdUUVZsD3Y:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/2657Productions?d=TzevzKxY174" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/2657Productions?a=MrtfNBylC5c:kpdUUVZsD3Y:bAAVSKdHlY4"><img src="http://feeds.feedburner.com/~ff/2657Productions?i=MrtfNBylC5c:kpdUUVZsD3Y:bAAVSKdHlY4" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/2657Productions/~4/MrtfNBylC5c" height="1" width="1"/>]]></content:encoded> <wfw:commentRss>http://news.mrdwab.com/2011/06/15/on-the-trucks-around-town/feed/</wfw:commentRss> <slash:comments>0</slash:comments> <feedburner:origLink>http://news.mrdwab.com/2011/06/15/on-the-trucks-around-town/</feedburner:origLink></item> <item><title>Stratified random sampling in R from a data frame</title><link>http://feedproxy.google.com/~r/2657Productions/~3/yEk9eTGAtoU/</link> <comments>http://news.mrdwab.com/2011/05/20/stratified-random-sampling-in-r-from-a-data-frame/#comments</comments> <pubDate>Fri, 20 May 2011 18:01:21 +0000</pubDate> <dc:creator>Ananda</dc:creator> <category><![CDATA[Geekiness]]></category> <category><![CDATA[Useless Knowledge]]></category> <category><![CDATA[code]]></category> <category><![CDATA[R]]></category> <category><![CDATA[R functions]]></category> <category><![CDATA[sampling]]></category> <category><![CDATA[statistics]]></category> <category><![CDATA[stratified sampling]]></category> <guid isPermaLink="false">http://news.mrdwab.com/?p=1174</guid> <description><![CDATA[After a little bit more work, there&#8217;s a new stratified random sampling function, this one letting you sample from a data frame, returning all the variables for each of your samples as a nice data frame that you can continue &#8230; <a
href="http://news.mrdwab.com/2011/05/20/stratified-random-sampling-in-r-from-a-data-frame/">Continue reading <span
class="meta-nav">&#8594;</span></a>]]></description> <content:encoded><![CDATA[<p>After a little bit more work, there&#8217;s a new stratified random sampling function, this one letting you sample from a data frame, returning all the variables for each of your samples as a nice data frame that you can continue working on as usual.</p><p>Get the function at <a
href="http://news.mrdwab.com/stratified">http://news.mrdwab.com/stratified</a>. Usage notes in the head of the function.</p><p><span
id="more-1174"></span></p><p>Here&#8217;s the function:</p><pre><code>stratified = function(df, id, group, size, seed="NULL", ...) {
  #  USE: * Specify your data frame, ID variable (as column number),
  #   and grouping variable (as column number) as the first three
  #   arguments.
  #    * Decide on your sample size. For a sample proportional to
  #   the population, enter "size" as a decimal. For an equal number
  #   of samples from each group, enter "size" as a whole number.
  #    * Decide on if you want to use a seed or not. If not, leave
  #   blank or type "NULL" (with quotes).
  #
  #  Example 1: To sample 10% of each group from a data frame named
  #    "z", where the ID variable is the first variable, the
  #    grouping variable is the fourth variable, and the desired
  #    seed is "1", use:
  #
  #     &gt; stratified(z, 1, 4, .1, 1)
  #
  #  Example 2: Run the same sample as above but without a seed:
  #
  #     &gt; stratified(z, 1, 4, .1)
  #
  #  Example 3: To sample 5 from each group from a data frame named
  #    "z", where the ID variable is the first variable, the
  #    grouping variable is the third variable, and the desired
  #    seed is 2, use:
  #
  #     &gt; stratified(z, 1, 3, 5, 2)
  #
  #  NOTE: Not tested on datasets with LOTS of groups or with HUGE
  #  differences in group sizes. Probably INCREDIBLY inefficient.
  k = unstack(data.frame(as.vector(df[id]), as.vector(df[group])))
  l = length(k)
  results = vector("list", l)
  if (seed == "NULL" &amp; size &lt; 1) {
    for (i in 1:length(k)) {
      N = k[[i]]
      n = round(length(N)*size)
      results[[i]] = list(sample(N, n, ...))
    }
  } else if (seed == "NULL" &amp; size &gt;= 1) {
    for (i in 1:length(k)) {
      N = k[[i]]
      results[[i]] = list(sample(N, size, ...))
    }
  } else if (size &lt; 1) {
    for (i in 1:length(k)) {
      set.seed(seed)
      N = k[[i]]
      n = round(length(N)*size)
      results[[i]] = list(sample(N, n, ...))
    }
  } else if (size &gt;= 1) {
    for (i in 1:length(k)) {
      set.seed(seed)
      N = k[[i]]
      results[[i]] = list(sample(N, size, ...))
    }
  }
  z = data.frame(c(unlist(results)))
  names(z) = names(df[id])
  w = merge(df, z)
  w[order(w[group]), ]
}
</code></pre><p>And here are some examples of the function in action:</p><pre><code>source("http://news.mrdwab.com/stratified")
# Make up some data
dat = data.frame(A = 1:100,
                 B = sample(c("AA", "BB", "CC", "DD", "EE"), 100,
                            replace=T),
                 C = rnorm(100),
                 D = abs(round(rnorm(100), digits=1)),
                 E = sample(c("CA", "NY", "TX"), 100, replace=T))
# view the first few rows
head(dat)
# A  B     C   D  E
# 1 1 CC -0.07870439 0.6 NY
# 2 2 CC -0.65048634 0.3 TX
# 3 3 EE  1.02703616 1.3 NY
# 4 4 BB -1.08696775 0.4 TX
# 5 5 CC  0.56741795 0.2 CA
# 6 6 AA -0.46448941 0.5 TX
# Sample 10% from each group from variable B, no seed
stratified(dat, 1, 2, .1)
# A  B     C   D  E
# 2   6 AA -0.46448941 0.5 TX
# 7  71 AA  1.98128479 2.1 CA
# 5  53 BB  1.00539398 0.7 NY
# 10 97 BB  0.68252675 1.9 NY
# 1   1 CC -0.07870439 0.6 NY
# 4  42 CC -2.00256854 0.3 TX
# 8  76 DD -0.84151459 0.2 NY
# 9  95 DD -0.47276142 0.3 CA
# 11 99 DD  1.05173419 2.1 TX
# 3  10 EE -0.69079473 1.1 TX
# 6  57 EE -0.38210921 1.5 CA
# Sample 10% from each group from variable E, seed of 1
stratified(dat, 1, 5, .1, 1)
# A  B    C   D  E
# 4  33 AA  1.6105099 0.5 CA
# 7  48 AA  0.3128274 0.6 CA
# 9  62 DD  0.4673061 0.0 CA
# 10 86 EE  0.4047880 1.6 CA
# 3  28 AA -1.6815553 0.3 NY
# 5  36 AA  0.3307508 0.3 NY
# 8  53 BB  1.0053940 0.7 NY
# 1  21 DD  0.5229282 1.2 TX
# 2  27 BB  0.8678977 0.7 TX
# 6  44 DD -0.5790353 0.9 TX
# You can also be verbose if it helps you remember what you're doing
stratified(df=dat, id=1, group=5, size=.1, seed=1)
# A  B    C   D  E
# 4  33 AA  1.6105099 0.5 CA
# 7  48 AA  0.3128274 0.6 CA
# 9  62 DD  0.4673061 0.0 CA
# 10 86 EE  0.4047880 1.6 CA
# 3  28 AA -1.6815553 0.3 NY
# 5  36 AA  0.3307508 0.3 NY
# 8  53 BB  1.0053940 0.7 NY
# 1  21 DD  0.5229282 1.2 TX
# 2  27 BB  0.8678977 0.7 TX
# 6  44 DD -0.5790353 0.9 TX
</code></pre><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/2657Productions?a=yEk9eTGAtoU:rGn30-HzPzc:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/2657Productions?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/2657Productions?a=yEk9eTGAtoU:rGn30-HzPzc:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/2657Productions?i=yEk9eTGAtoU:rGn30-HzPzc:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/2657Productions?a=yEk9eTGAtoU:rGn30-HzPzc:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/2657Productions?i=yEk9eTGAtoU:rGn30-HzPzc:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/2657Productions?a=yEk9eTGAtoU:rGn30-HzPzc:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/2657Productions?d=TzevzKxY174" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/2657Productions?a=yEk9eTGAtoU:rGn30-HzPzc:bAAVSKdHlY4"><img src="http://feeds.feedburner.com/~ff/2657Productions?i=yEk9eTGAtoU:rGn30-HzPzc:bAAVSKdHlY4" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/2657Productions/~4/yEk9eTGAtoU" height="1" width="1"/>]]></content:encoded> <wfw:commentRss>http://news.mrdwab.com/2011/05/20/stratified-random-sampling-in-r-from-a-data-frame/feed/</wfw:commentRss> <slash:comments>7</slash:comments> <feedburner:origLink>http://news.mrdwab.com/2011/05/20/stratified-random-sampling-in-r-from-a-data-frame/</feedburner:origLink></item> <item><title>Stratified Random Sampling in R–A Function in Progress</title><link>http://feedproxy.google.com/~r/2657Productions/~3/-wyu5FBhqlg/</link> <comments>http://news.mrdwab.com/2011/05/15/stratified-random-sampling-in-r-beta/#comments</comments> <pubDate>Sun, 15 May 2011 10:16:02 +0000</pubDate> <dc:creator>Ananda</dc:creator> <category><![CDATA[(all categories)]]></category> <category><![CDATA[Geekiness]]></category> <category><![CDATA[Useless Knowledge]]></category> <category><![CDATA[code]]></category> <category><![CDATA[experiments]]></category> <category><![CDATA[R]]></category> <category><![CDATA[R functions]]></category> <category><![CDATA[sampling]]></category> <category><![CDATA[statistics]]></category> <category><![CDATA[tapply()]]></category> <guid isPermaLink="false">http://news.mrdwab.com/?p=1141</guid> <description><![CDATA[IMPORTANT: This is here mostly to remind me of how I solved my problem. You should read Stratified random sampling in R from a data frame if you really want to use this function. I know that sampling is quite &#8230; <a
href="http://news.mrdwab.com/2011/05/15/stratified-random-sampling-in-r-beta/">Continue reading <span
class="meta-nav">&#8594;</span></a>]]></description> <content:encoded><![CDATA[<blockquote><p><strong>IMPORTANT</strong>: This is here mostly to remind me of how I solved my problem. You should read <a
href="http://news.mrdwab.com/2011/05/20/stratified-random-sampling-in-r-from-a-data-frame/" title="Stratified random sampling in R from a data frame">Stratified random sampling in R from a data frame</a> if you really want to use this function.</p></blockquote><p>I know that sampling is quite complex, and I will admit that I know very little about its complexities. Fortunately, software like <a
href="http://www.r-project.org">R</a> lets you draw <a
href="http://news.mrdwab.com/2009/11/29/simple-sampling-with-r/" title="Simple sampling with R">simple random samples</a> pretty easily, either <a
href="http://news.mrdwab.com/2009/11/30/sampling-with-replacement-in-r/" title="Sampling with replacement in R">either with</a> or without replacement. Unfortunately, I could not find any feature to allow me to do simple stratified random sampling, at least not with the features I was looking for. Fortunately again, with a little bit of experimenting, it can be pretty easy to learn how to write functions in R when a direct solution does not present itself.</p><p>This post shares my initial &#8220;work-in-progress&#8221; on writing an R function for stratified sampling.</p><p><span
id="more-1141"></span></p><h2>The problem&#8230;</h2><p>Here&#8217;s the minimum that I was hoping for:</p><ul><li>I wanted to be able to draw both a proportional sample (which is more common, for it allows you to make generalizations about the population as a whole) as well as a fixed-size sample (which less common, but it is useful for making comparisons across groups).</li><li>I often use a seed when sampling, so I wanted that to be a part of the function.</li><li>I wanted the output to be the same as if I were to sample from each group individually.<ul><li>I was hoping that my output could be stored as a new object that I could then reuse (either a list or a data frame, preferably the latter).</li></ul></li></ul><p>My initial searches directed me to <a
href="http://yihui.name/r/stat/sampling_survey/stratified/index.htm" target="_blank">Yihui Xie&#8217;s page on stratified sampling using tapply()</a>. However, this option did not satisfy my needs. As far as I could figure, it only allowed me to take a fixed sample size. Also, I wasn&#8217;t totally satisfied with the output.</p><p>Consider the following. In Yihui Xie&#8217;s example, there is a difference between the results one would get if they sampled from each group separately, but using the same seed.</p><pre><code>dat = data.frame(x = 1:15, stratum = gl(3, 5))
dat
##     x stratum
## 1   1       1
## 2   2       1
## 3   3       1
## 4   4       1
## 5   5       1
## 6   6       2
## 7   7       2
## 8   8       2
## 9   9       2
## 10 10       2
## 11 11       3
## 12 12       3
## 13 13       3
## 14 14       3
## 15 15       3
set.seed(1)
tapply(dat$x, dat$stratum, sample, size = 3)
## $`1`
## [1] 2 5 4
##
## $`2`
## [1] 10  6  8
##
## $`3`
## [1] 15 13 12
##
# Compare with what we get when we sample individually:
set.seed(1)
sample(1:5, 3)
## [1] 2 5 4
set.seed(1)
sample(6:10, 3)
## [1]  7 10  9
set.seed(1)
sample(11:15, 3)
## [1] 12 15 14
# But notice this
set.seed(1)
sample(1:5, 3)
## [1] 2 5 4
sample(6:10, 3)
## [1] 10  6  8
sample(11:15, 3)
## [1] 15 13 12
</code></pre><p>Essentially, the <code>tapply</code> version and the <code>set.seed</code> once version both set the seed for that session or until a new seed is provided. This is fine, but if one does an intermediate step that involves random number generation you won&#8217;t get the same results. For example:</p><pre><code>set.seed(1)
sample(1:5, 3)
## [1] 2 5 4
sample(6:10, 3)
## [1] 10  6  8
rnorm(10)
##  [1]  1.5953  0.3295 -0.8205  0.4874  0.7383  0.5758 -0.3054  1.5118
##  [9]  0.3898 -0.6212
sample(11:15, 3)
## [1] 11 12 13
</code></pre><h2>Stratified sampling, Mr. DWAB style</h2><p>The solution I arrived at is to use &#8220;<code>unstack()</code>&#8221; and a few conditional loops to take the samples.</p><p>And, without more rambling, here&#8217;s what I came up with.</p><pre><code>stratified = function(df, size, seed, dframe=FALSE, ...) {
  # USE: Start with a data frame with your cases in one
  # column and your groups in another column. Decide on
  # if you want to use a seed or not. If not, seed should
  # be "NO" (with quotes). Decide on if you want your
  # output as a data frame or not; by default, dframe is
  # set to "FALSE". To take a sample proportional to the
  # population size in each group, enter "size" as a
  # decimal. Otherwise, enter size as a whole number.
  #
  # Example 1a: To sample 10% of each group from a data
  # frame named "z" and using a seed of "1", use:
  #   &gt; stratified(z, .1, 1)
  # Example 1b: To run the same sample as above but display
  # the result as a data.frame, use:
  #   &gt; stratified(z, .1, 1, T)
  # Example 2: To sample 10% of each group from a data.frame
  # named "z" and using no seed, use:
  #   &gt; stratified(z, .1, "NO")
  # Example 3: To sample 5 from each group from a data.frame
  # named "z" and using a seed of 30, use:
  #   &gt; stratified(z, 5, 30)
  #
  # NOTE: Not recommended for datasets with LOTS of groups
  # or with HUGE differences in group sizes.
  k = unstack(df)
  if (dframe == FALSE) {
    if (seed == "NO" &amp; size &lt; 1) {
      for (i in 1:length(k)) {
        N = k[[i]]
        n = round(length(N)*size)
        pre = structure(list("Group" = names(k[i]),
                             "Population Size" = length(k[[i]]),
                             "Sample Size" = n,
                             Seed = seed,
                             Sample = sample(N, n, ...)),
                        class = "power.htest")
        print(pre)
      }
    } else if (seed == "NO" &amp; size &gt;= 1) {
      for (i in 1:length(k)) {
        N = k[[i]]
        pre = structure(list("Group" = names(k[i]),
                             "Population Size" = length(k[[i]]),
                             "Sample Size" = size,
                             Seed = seed,
                             Sample = sample(N, size, ...)),
                        class = "power.htest")
        print(pre)
      }
    } else if (size &lt; 1) {
      for (i in 1:length(k)) {
        set.seed(seed)
        N = k[[i]]
        n = round(length(N)*size)
        pre = structure(list("Group" = names(k[i]),
                             "Population Size" = length(k[[i]]),
                             "Sample Size" = n,
                             Seed = seed,
                             Sample = sample(N, n, ...)),
                        class = "power.htest")
        print(pre)
      }
    } else if (size &gt;= 1) {
      for (i in 1:length(k)) {
        set.seed(seed)
        N = k[[i]]
        pre = structure(list("Group" = names(k[i]),
                             "Population Size" = length(k[[i]]),
                             "Sample Size" = size,
                             Seed = seed,
                             Sample = sample(N, size, ...)),
                        class = "power.htest")
        print(pre)
      }
    }
  } else {
    if (seed == "NO" &amp; size &lt; 1) {
      for (i in 1:length(k)) {
        N = k[[i]]
        n = round(length(N)*size)
        res = data.frame(names(k[i]), sample(N, n, ...))
        names(res) = c("Group", "Samples")
        print(res)
      }
    } else if (seed == "NO" &amp; size &gt;= 1) {
      for (i in 1:length(k)) {
        N = k[[i]]
        res = data.frame(names(k[i]), sample(N, size, ...))
        names(res) = c("Group", "Samples")
        print(res)
      }
    } else if (size &lt; 1) {
      for (i in 1:length(k)) {
        set.seed(seed)
        N = k[[i]]
        n = round(length(N)*size)
        res = data.frame(names(k[i]), sample(N, n, ...))
        names(res) = c("Group", "Samples")
        print(res)
      }
    } else if (size &gt;= 1) {
      for (i in 1:length(k)) {
        set.seed(seed)
        N = k[[i]]
        res = data.frame(names(k[i]), sample(N, size, ...))
        names(res) = c("Group", "Samples")
        print(res)
      }
    }
  }
}
</code></pre><p>You can load the function by typing:</p><pre><code>source("http://news.mrdwab.com/stratified-beta")
</code></pre><h2>And now, to test it&#8230;</h2><p>Let&#8217;s generate some dummy data and see what we can come up with. The function takes the following arguments (in the following order):</p><ul><li><code>df</code>: The source data frame, with the first column being the IDs and the second column being the groups.</li><li><code>size</code>: The sample size you want, either as a percentage (for proportional sampling–expressed as a decimal) or as a whole number.</li><li><code>seed</code>: The seed you want to use. If you don&#8217;t want to use a seed, enter &#8220;<code>NO</code>&#8220;.</li><li><code>dframe</code>: What format you want the output in, either a list or a data frame. Defaults to a list (<code>dframe=FALSE</code>), which is better at the moment since the data frame option is not working the way I expect it to yet.</li></ul><p>Here we go!</p><pre><code># Generate some data
a = 1:100
set.seed(123)
b = sample(c("a", "b", "c", "d"), 100, replace = T)
z = data.frame(a, b)
# Check how big each group is
table(z$b)
##
##  a  b  c  d
## 26 27 20 27
# Make sure the function is loaded before you continue!
# source("http://news.mrdwab.com/stratified-beta")
# Take a 15% sample and use a seed of 1
stratified(z, .15, 1)
##
##
##
##           Group = a
## Population Size = 26
##     Sample Size = 4
##            Seed = 1
##          Sample = 38, 45, 54, 81
##
##
##
##
##           Group = b
## Population Size = 27
##     Sample Size = 4
##            Seed = 1
##          Sample = 39, 43, 60, 79
##
##
##
##
##           Group = c
## Population Size = 20
##     Sample Size = 3
##            Seed = 1
##          Sample = 23, 26, 33
##
##
##
##
##           Group = d
## Population Size = 27
##     Sample Size = 4
##            Seed = 1
##          Sample = 21, 31, 53, 71
##
# Take a sample of 5 from each group and use a seed of 1
stratified(z, 5, 1)
##
##
##
##           Group = a
## Population Size = 26
##     Sample Size = 5
##            Seed = 1
##          Sample = 38, 45, 54, 81, 30
##
##
##
##
##           Group = b
## Population Size = 27
##     Sample Size = 5
##            Seed = 1
##          Sample = 39, 43, 60, 79, 19
##
##
##
##
##           Group = c
## Population Size = 20
##     Sample Size = 5
##            Seed = 1
##          Sample = 23, 26, 33, 78, 14
##
##
##
##
##           Group = d
## Population Size = 27
##     Sample Size = 5
##            Seed = 1
##          Sample = 21, 31, 53, 71, 11
##
# Take a sample of 15 from each group, with replacement, and a seed of 1
stratified(z, 15, 1, replace=T)
##
##
##
##           Group = a
## Population Size = 26
##     Sample Size = 15
##            Seed = 1
##          Sample = 38, 45, 56, 91, 35, 91, 96, 74, 62, 15, 35, 30, 74, 45, 81
##
##
##
##
##           Group = b
## Population Size = 27
##     Sample Size = 15
##            Seed = 1
##          Sample = 39, 44, 63, 93, 29, 93, 95, 66, 64, 3, 29, 19, 70, 44, 77
##
##
##
##
##           Group = c
## Population Size = 20
##     Sample Size = 15
##            Seed = 1
##          Sample = 23, 26, 55, 94, 22, 92, 94, 72, 61, 9, 22, 14, 72, 26, 78
##
##
##
##
##           Group = d
## Population Size = 27
##     Sample Size = 15
##            Seed = 1
##          Sample = 21, 32, 58, 88, 16, 88, 89, 65, 59, 4, 16, 11, 67, 32, 69
##
# Take a sample of 10% from each group, using a seed of 1,
# and display the output as a data frame
stratified(z, .1, 1, dframe=T)
##   Group Samples
## 1     a      38
## 2     a      45
## 3     a      54
##   Group Samples
## 1     b      39
## 2     b      43
## 3     b      60
##   Group Samples
## 1     c      23
## 2     c      26
##   Group Samples
## 1     d      21
## 2     d      31
## 3     d      53
</code></pre><p>Everything seems OK.</p><h2>Replicating the results from <code>tapply()</code></h2><p>I mentioned earlier that the results are different from what you would get if you were to use the <code>tapply()</code> function. However, it is easy to get the same results using this stratified function–simply move your &#8220;seed&#8221; outside of the function (enter seed as <code>"NO"</code> [with quotes] and instead, use <code>set.seed()</code> as you normally would).</p><pre><code># See what tapply() gives us
set.seed(1); tapply(z$a, z$b, sample, size = 4)
## $a
## [1] 38 45 54 81
##
## $b
## [1] 29 86 95 63
##
## $c
## [1] 61  9 14 92
##
## $d
## [1] 67 31 68 34
##
# The normal usage for the stratified function
stratified(z, 4, 1, dframe = T)
##   Group Samples
## 1     a      38
## 2     a      45
## 3     a      54
## 4     a      81
##   Group Samples
## 1     b      39
## 2     b      43
## 3     b      60
## 4     b      79
##   Group Samples
## 1     c      23
## 2     c      26
## 3     c      33
## 4     c      78
##   Group Samples
## 1     d      21
## 2     d      31
## 3     d      53
## 4     d      71
# Getting the same results as tapply()
# Set the seed before using the function,
# and set the seed for the function as "NO"
set.seed(1); stratified(z, 4, "NO", dframe = T)
##   Group Samples
## 1     a      38
## 2     a      45
## 3     a      54
## 4     a      81
##   Group Samples
## 1     b      29
## 2     b      86
## 3     b      95
## 4     b      63
##   Group Samples
## 1     c      61
## 2     c       9
## 3     c      14
## 4     c      92
##   Group Samples
## 1     d      67
## 2     d      31
## 3     d      68
## 4     d      34
</code></pre><p>So, set your seed according to what you want to replicate.</p><h2>The unfortunate&#8230;</h2><p>There are some advantages to each of the output formats. I&#8217;ve set up the list to be quite verbose, which is useful with the proportionate sampling since it shows us how many samples have been taken from each group. The data frame output format, on the other hand, is quite compact.</p><p>What I still need to figure out, though, is why R won&#8217;t store my output. I suspect that it has something to do with how my loops are set up. I assume that somewhere, I need to add something like an rbind command.</p><p>When the time is right, I will be sure to post what I&#8217;ve found.</p> <div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/2657Productions?a=-wyu5FBhqlg:wjrKfapmaSY:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/2657Productions?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/2657Productions?a=-wyu5FBhqlg:wjrKfapmaSY:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/2657Productions?i=-wyu5FBhqlg:wjrKfapmaSY:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/2657Productions?a=-wyu5FBhqlg:wjrKfapmaSY:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/2657Productions?i=-wyu5FBhqlg:wjrKfapmaSY:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/2657Productions?a=-wyu5FBhqlg:wjrKfapmaSY:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/2657Productions?d=TzevzKxY174" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/2657Productions?a=-wyu5FBhqlg:wjrKfapmaSY:bAAVSKdHlY4"><img src="http://feeds.feedburner.com/~ff/2657Productions?i=-wyu5FBhqlg:wjrKfapmaSY:bAAVSKdHlY4" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/2657Productions/~4/-wyu5FBhqlg" height="1" width="1"/>]]></content:encoded> <wfw:commentRss>http://news.mrdwab.com/2011/05/15/stratified-random-sampling-in-r-beta/feed/</wfw:commentRss> <slash:comments>0</slash:comments> <feedburner:origLink>http://news.mrdwab.com/2011/05/15/stratified-random-sampling-in-r-beta/</feedburner:origLink></item> </channel> </rss>
