<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-8963258932818536016</id><updated>2024-10-24T19:25:52.087+09:00</updated><title type='text'>バイオインフォマティクス、勉強中</title><subtitle type='html'>素人です。手探りで勉強中です。</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://bioinfomemoblog.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8963258932818536016/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://bioinfomemoblog.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/8963258932818536016/posts/default?start-index=26&amp;max-results=25&amp;redirect=false'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>39</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-8963258932818536016.post-1274544817032780107</id><published>2017-07-21T00:00:00.000+09:00</published><updated>2017-07-21T15:03:42.939+09:00</updated><title type='text'>エンコーディングの問題</title><content type='html'>たまたま入手したファイルが開けず苦労した。&lt;br /&gt;
mi で調べると、エンコーディングが Windows-1252 だった。&lt;br /&gt;
&lt;br /&gt;
これを R で解決する方法。&lt;br /&gt;
readLines() で encoding を指定して読み込み、write() で書き出す。&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;gff &amp;lt;- readLines(&quot;XXX.gff3&quot;, encoding = &quot;windows-1252&quot;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;write(gff, file = &quot;XXX_UTF8.gff3&quot;)&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
これでとりあえず問題回避できる。&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div id=&quot;UMS_TOOLTIP&quot; style=&quot;background-color: transparent; background-position: initial initial; background-repeat: initial initial; cursor: pointer; left: -100000px; position: absolute; top: -100000px; z-index: 2147483647;&quot;&gt;
&lt;img class=&quot;UMSRatingIcon&quot; id=&quot;ums_img_tooltip&quot; /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://bioinfomemoblog.blogspot.com/feeds/1274544817032780107/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='http://bioinfomemoblog.blogspot.com/2017/07/blog-post.html#comment-form' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8963258932818536016/posts/default/1274544817032780107'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8963258932818536016/posts/default/1274544817032780107'/><link rel='alternate' type='text/html' href='http://bioinfomemoblog.blogspot.com/2017/07/blog-post.html' title='エンコーディングの問題'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8963258932818536016.post-1101297978122848301</id><published>2017-07-06T00:00:00.000+09:00</published><updated>2017-07-06T15:25:26.239+09:00</updated><title type='text'>homebrew: tbl2asn installation failed</title><content type='html'>homebrew で tbl2asn をインストールできないときの対処法。&lt;br /&gt;
When installation of tbl2asn through homobrew failed.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;Error: SHA256 mismatch&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;Expected: 429d63ee3c36d1f2f6322c62c6089d5ee8a8b089e5cc9373e298e017bcbbb9ec&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;Actual: bfaff2308fd58b94730639b9c6b520ca1884ede9979389cfc9bc4902ae75702c&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;Archive: /Users/XXX/Library/Caches/Homebrew/tbl2asn-25.3.gz&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;To retry an incomplete download, remove the file above.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
下のファイルをテキストで開いて、変更を加える。&lt;br /&gt;
Open the .rb file as a text and change the sha256 as bellow.&lt;br /&gt;
&lt;br /&gt;
File location:&lt;br /&gt;
/usr/local/Homebrew/Library/Taps/homebrew/homebrew-science/tbl2asn.rb&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;### original&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;# &amp;nbsp; if OS.mac?&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;# &amp;nbsp; &amp;nbsp; url &quot;ftp://ftp.ncbi.nih.gov/toolbox/ncbi_tools/converters/by_program/tbl2asn/mac.tbl2asn.gz&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;# &amp;nbsp; &amp;nbsp; sha256 &quot;429d63ee3c36d1f2f6322c62c6089d5ee8a8b089e5cc9373e298e017bcbbb9ec&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;### fixed&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;# &amp;nbsp; if OS.mac?&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;# &amp;nbsp; &amp;nbsp; url &quot;ftp://ftp.ncbi.nih.gov/toolbox/ncbi_tools/converters/by_program/tbl2asn/mac.tbl2asn.gz&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;# &amp;nbsp; &amp;nbsp; sha256 &quot;bfaff2308fd58b94730639b9c6b520ca1884ede9979389cfc9bc4902ae75702c&quot;&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div id=&quot;UMS_TOOLTIP&quot; style=&quot;background-color: transparent; background-position: initial initial; background-repeat: initial initial; cursor: pointer; left: -100000px; position: absolute; top: -100000px; z-index: 2147483647;&quot;&gt;
&lt;img class=&quot;UMSRatingIcon&quot; id=&quot;ums_img_tooltip&quot; /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://bioinfomemoblog.blogspot.com/feeds/1101297978122848301/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='http://bioinfomemoblog.blogspot.com/2017/07/homebrew-tbl2asn-installation-failed.html#comment-form' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8963258932818536016/posts/default/1101297978122848301'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8963258932818536016/posts/default/1101297978122848301'/><link rel='alternate' type='text/html' href='http://bioinfomemoblog.blogspot.com/2017/07/homebrew-tbl2asn-installation-failed.html' title='homebrew: tbl2asn installation failed'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8963258932818536016.post-2865325452024651842</id><published>2016-08-03T00:00:00.000+09:00</published><updated>2016-08-03T16:37:04.374+09:00</updated><title type='text'>R: pdflatex is not available</title><content type='html'>Rで「&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;pdflatex is not available&lt;/span&gt;」というエラーに遭遇したときの対処方法。&lt;br /&gt;
&lt;a href=&quot;https://www.r-bloggers.com/building-r-packages-missing-path-to-pdflatex/&quot; target=&quot;_blank&quot;&gt;こちら&lt;/a&gt;のサイトを参考にした。&lt;br /&gt;
&lt;br /&gt;
まず、ターミナルで「pdflatex」の場所を確かめる。&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;which&lt;/span&gt;を使う。&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;$ which pdflatex&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;/usr/texbin/pdflatex&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
ちなみに「R」の場所はこちら。&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;$ which r&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;/usr/bin/r&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
「pdflatex」が入っていることを確認した。mac側ではなくR側の問題ということになる。&lt;br /&gt;
&lt;br /&gt;
Rがソフトウェアを認識するかどうかは、&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;Sys.which()&lt;/span&gt;で知ることができる。&lt;br /&gt;
たとえば「R」を探すなら、&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;gt; Sys.which(&quot;r&quot;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;r&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&quot;/usr/bin/r&quot;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
という具合。ターミナルでみたときと同じ。&lt;br /&gt;
&lt;br /&gt;
上のエラーが出ている状態で「pdflatex」を探してみると、&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;gt; Sys.which(&quot;pdflatex&quot;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;pdflatex&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &quot;&quot;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
どうやら認識していないことがわかる。&lt;br /&gt;
&lt;br /&gt;
これはPATHの問題。RのPATHを調べるには、&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;Sys.getenv()&lt;/span&gt;を使う。&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;gt; Sys.getenv(&quot;PATH&quot;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;[1] &quot;/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin&quot;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
いくつかPATHがあるが、「/usr/texbin」がない。&lt;br /&gt;
これがエラーの元凶。&lt;br /&gt;
&lt;br /&gt;
PATHを通す作業を行う。そのためには、&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;Sys.setenv()&lt;/span&gt;を使う。&lt;br /&gt;
既存のPATHと「/usr/texbin」を&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;paste()&lt;/span&gt;で繋げるところがRっぽい。&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;Sys.setenv(PATH = paste(Sys.getenv(&quot;PATH&quot;), &quot;/usr/texbin&quot;, sep=&quot;:&quot;))&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
これで、PATHが追加された。&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;gt; Sys.getenv(&quot;PATH&quot;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;[1] &quot;/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/texbin&quot;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Rが「pdflatex」の場所を知ることができるようになった。&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;gt; Sys.which(&quot;pdflatex&quot;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; pdflatex&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&quot;/usr/texbin/pdflatex&quot;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
これで、「&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;pdflatex is not available&lt;/span&gt;」というエラーが出なくなる。&lt;br /&gt;
&lt;br /&gt;
&lt;div id=&quot;UMS_TOOLTIP&quot; style=&quot;background-color: transparent; background-position: initial initial; background-repeat: initial initial; cursor: pointer; left: -100000px; position: absolute; top: -100000px; z-index: 2147483647;&quot;&gt;
&lt;img class=&quot;UMSRatingIcon&quot; id=&quot;ums_img_tooltip&quot; /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://bioinfomemoblog.blogspot.com/feeds/2865325452024651842/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='http://bioinfomemoblog.blogspot.com/2016/08/r-pdflatex-is-not-available.html#comment-form' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8963258932818536016/posts/default/2865325452024651842'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8963258932818536016/posts/default/2865325452024651842'/><link rel='alternate' type='text/html' href='http://bioinfomemoblog.blogspot.com/2016/08/r-pdflatex-is-not-available.html' title='R: pdflatex is not available'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8963258932818536016.post-6138113803234655265</id><published>2016-07-22T00:00:00.000+09:00</published><updated>2016-07-22T15:25:11.762+09:00</updated><title type='text'>R: オブジェクトのサイズを考える</title><content type='html'>関数object.size()を使えば、オブジェクトのサイズを知ることができる。大きなデータを扱う場合、サイズは意識しておいた方が良いと思う。&lt;br /&gt;
&lt;br /&gt;
とりあえず、character vectorをつくってサイズを眺めてみる。&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;# &amp;gt; x &amp;lt;- &quot;&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;# &amp;gt; nchar(x)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;# [1] 0&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;# &amp;gt; object.size(x)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;# 96 bytes&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;# &amp;gt; object.size(&quot;1&quot;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;# 96 bytes&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;# &amp;gt; object.size(&quot;1234567&quot;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;# 96 bytes&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;# &amp;gt; object.size(&quot;12345678&quot;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;# 104 bytes&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;# &amp;gt; object.size(&quot;123456789012345&quot;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;# 104 bytes&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;# &amp;gt; object.size(&quot;1234567890123456&quot;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;# 120 bytes&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;# &amp;gt; object.size(&quot;1234567890123456789012345678901&quot;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;# 120 bytes&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;# &amp;gt; object.size(&quot;12345678901234567890123456789012&quot;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;# 136 bytes&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
文字が長くなると表示しづらいので、for()で伸ばしてnchar()で文字数を確認し、object.size()で調査する。&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;# &amp;gt; x &amp;lt;- &quot;&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;# &amp;gt; for(i in 1:47) x &amp;lt;- paste(x, &quot;a&quot;, sep = &quot;&quot;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;# &amp;gt; nchar(x)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;# [1] 47&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;# &amp;gt; object.size(x)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;# 136 bytes&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;# &amp;gt; x &amp;lt;- &quot;&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;# &amp;gt; for(i in 1:48) x &amp;lt;- paste(x, &quot;a&quot;, sep = &quot;&quot;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;# &amp;gt; nchar(x)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;# [1] 48&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;# &amp;gt; object.size(x)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;# 152 bytes&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;# &amp;gt; x &amp;lt;- &quot;&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;# &amp;gt; for(i in 1:63) x &amp;lt;- paste(x, &quot;a&quot;, sep = &quot;&quot;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;# &amp;gt; nchar(x)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;# [1] 63&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;# &amp;gt; object.size(x)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;# 152 bytes&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;# &amp;gt; x &amp;lt;- &quot;&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;# &amp;gt; for(i in 1:64) x &amp;lt;- paste(x, &quot;a&quot;, sep = &quot;&quot;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;# &amp;gt; nchar(x)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;# [1] 64&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;# &amp;gt; object.size(x)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;# 216 bytes&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
文字の数とサイズは、どうやら以下の関係になっている。&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;0~7: &amp;nbsp; 96 bytes&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;8~15: &amp;nbsp;104 bytes (+8)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;16~31: 120 bytes (+16)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;32~47: 136 bytes (+16)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;48~63: 152 bytes (+16)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;64~?: &amp;nbsp;216 bytes (+64)&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
一見すると秩序がありそう。&lt;br /&gt;
ということで、以下のコマンドでプロットしてみる。&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;main &amp;lt;- &quot;Relationship between nchar and object.size&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;sub &amp;lt;- c(&quot;64(blue), 128(green), 136(red), 144(orange)&quot;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;y &amp;lt;- &quot;&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;plot(x = nchar(y), y = object.size(y),&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;nbsp; &amp;nbsp;sub = sub, main = main,&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;nbsp; &amp;nbsp;xlim = c(0,550), ylim = c(0,700), pch = 20)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;for(i in 1:550){&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;nbsp; &amp;nbsp;y &amp;lt;- paste(y, &quot;y&quot;, sep = &quot;&quot;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;nbsp; &amp;nbsp;points(x = nchar(y), y = object.size(y), pch = 20)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;abline(v = c(64, 128, 136, 144),&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;nbsp; &amp;nbsp;col = c(&quot;blue&quot;, &quot;green&quot;, &quot;red&quot;, &quot;orange&quot;))&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgAepvcqwHGZFnSY8htvJz1z5Ev32I27GbqlPuMST1RGMZYCBOgh7sLRZOPS7IIqsWBKPePZzsEOs6HmInCmau51fZR0nSv1TxTdMVtpk9ix3ssJYKUojpBK1-aLmqh9uRjuTbEWwihUJtE/s1600/20160721.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgAepvcqwHGZFnSY8htvJz1z5Ev32I27GbqlPuMST1RGMZYCBOgh7sLRZOPS7IIqsWBKPePZzsEOs6HmInCmau51fZR0nSv1TxTdMVtpk9ix3ssJYKUojpBK1-aLmqh9uRjuTbEWwihUJtE/s320/20160721.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
これはもう、本当に変なプロットになった。&lt;br /&gt;
どうやら、127文字を越えると取扱い方が変わるらしい。&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;# &amp;gt; x &amp;lt;- &quot;&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;# &amp;gt; for(i in 1:127) x &amp;lt;- paste(x, &quot;a&quot;, sep = &quot;&quot;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;# &amp;gt; nchar(x)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;# [1] 127&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;# &amp;gt; object.size(x)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;# 216 bytes&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;# &amp;gt; x &amp;lt;- &quot;&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;# &amp;gt; for(i in 1:128) x &amp;lt;- paste(x, &quot;a&quot;, sep = &quot;&quot;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;# &amp;gt; nchar(x)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;# [1] 128&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;# &amp;gt; object.size(x)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;# 224 bytes&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;# &amp;gt; x &amp;lt;- &quot;&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;# &amp;gt; for(i in 1:135) x &amp;lt;- paste(x, &quot;a&quot;, sep = &quot;&quot;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;# &amp;gt; nchar(x)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;# [1] 135&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;# &amp;gt; object.size(x)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;# 224 bytes&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;# &amp;gt; x &amp;lt;- &quot;&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;# &amp;gt; for(i in 1:136) x &amp;lt;- paste(x, &quot;a&quot;, sep = &quot;&quot;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;# &amp;gt; nchar(x)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;# [1] 136&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;# &amp;gt; object.size(x)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;# 232 bytes&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;# &amp;gt; x &amp;lt;- &quot;&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;# &amp;gt; for(i in 1:143) x &amp;lt;- paste(x, &quot;a&quot;, sep = &quot;&quot;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;# &amp;gt; nchar(x)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;# [1] 143&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;# &amp;gt; object.size(x)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;# 232 bytes&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;# &amp;gt; x &amp;lt;- &quot;&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;# &amp;gt; for(i in 1:144) x &amp;lt;- paste(x, &quot;a&quot;, sep = &quot;&quot;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;# &amp;gt; nchar(x)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;# [1] 144&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;# &amp;gt; object.size(x)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;# 240 bytes&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
まとめると、文字の数とサイズは以下の関係になっている。&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;0~7: &amp;nbsp; &amp;nbsp; &amp;nbsp;96 bytes&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;8~15: &amp;nbsp; &amp;nbsp; 104 bytes (+8)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;16~31: &amp;nbsp; &amp;nbsp;120 bytes (+16)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;32~47: &amp;nbsp; &amp;nbsp;136 bytes (+16)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;48~63: &amp;nbsp; &amp;nbsp;152 bytes (+16)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;64~127: &amp;nbsp; 216 bytes (+64)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;128~135: &amp;nbsp;224 bytes (+8)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;136~143: &amp;nbsp;232 bytes (+8)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;144~152: &amp;nbsp;240 bytes (+8)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;153~xxx: &amp;nbsp;8文字毎に8バイト増える。&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
基本的に１バイトに１文字が格納される計算になるのだが、そのオブジェクトの占有メモリは１文字毎に増えるのではない。あらかじめ決められた規則に則って、時には16文字分、あるいは64文字分のメモリが割り当てられる。しかも、どうやら128文字目以降は8文字単位でメモリの割り当てが増やされるらしい。&lt;br /&gt;
&lt;br /&gt;
もうひとつの奇妙な現象を見つけた。&lt;br /&gt;
以下のコマンドを実行してもらうとわかるのだが、ひとつのベクターが２つの文字列をもち、しかもそれらの文字列が同一であれば、オブジェクトサイズは期待値よりも小さい。もしかしてfactorとして管理してるのかなぁ。&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;x &amp;lt;- &quot;&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;for(i in 1:10) x &amp;lt;- paste(x, &quot;a&quot;, sep = &quot;&quot;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;y &amp;lt;- c(x, x)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;z &amp;lt;- c(x, paste(x, &quot;b&quot;, sep = &quot;&quot;))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;w &amp;lt;- c(paste(x, &quot;b&quot;, sep = &quot;&quot;), paste(x, &quot;b&quot;, sep = &quot;&quot;))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;x&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;y&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;z&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;w&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;nchar(x)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;nchar(y)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;nchar(z)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;nchar(w)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;object.size(x)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;object.size(y)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;object.size(z)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;object.size(w)&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://bioinfomemoblog.blogspot.com/feeds/6138113803234655265/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='http://bioinfomemoblog.blogspot.com/2016/07/r.html#comment-form' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8963258932818536016/posts/default/6138113803234655265'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8963258932818536016/posts/default/6138113803234655265'/><link rel='alternate' type='text/html' href='http://bioinfomemoblog.blogspot.com/2016/07/r.html' title='R: オブジェクトのサイズを考える'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgAepvcqwHGZFnSY8htvJz1z5Ev32I27GbqlPuMST1RGMZYCBOgh7sLRZOPS7IIqsWBKPePZzsEOs6HmInCmau51fZR0nSv1TxTdMVtpk9ix3ssJYKUojpBK1-aLmqh9uRjuTbEWwihUJtE/s72-c/20160721.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8963258932818536016.post-4351948132719348436</id><published>2016-07-20T00:00:00.000+09:00</published><updated>2016-07-22T13:53:19.845+09:00</updated><title type='text'>R: latticeのlevelplot()で枠を消す</title><content type='html'>表に入っているデータを俯瞰したいとき、レベルプロットが役に立つ。レベルプロットは&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;lattice&lt;/span&gt;パッケージの&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;levelplot()&lt;/span&gt;で実現できる。&lt;br /&gt;
&lt;br /&gt;
しかし通常のやり方だと関数内で縦と横がスケーリングされてしまうので、ピクセル単位で期待通りのサイズの絵を出力するのが難しい。&lt;br /&gt;
&lt;br class=&quot;Apple-interchange-newline&quot; /&gt;
マージンをゼロにしてプロット領域のみにし、プロットの外枠を消し、カラーキーを消すと、１ピクセルに１つの値を配置することができる。&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
R: lattice levelplot(), Remove the border line.&lt;br /&gt;
&lt;br /&gt;
When you would like to see the information in a table or matrix at a glance, draw a level plot. It can be done with the function levelplot() in the lattice package.&lt;br /&gt;
&lt;br /&gt;
It seems that the function automatically scales the plot, making it difficult to get a plot with defined scales.&lt;br /&gt;
&lt;br /&gt;
By removing the margins, border lines and colorkey, you can get a plot in which a square of 1 x 1 pixel is filled with a value-related color.&lt;br /&gt;
&lt;br /&gt;
# テスト用のマトリックスを作る。乱数の絶対値。&lt;br /&gt;
# Make a matrix with randomly produced values for a test.&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;x &amp;lt;- rnorm(20, mean = 0.5, sd = 0.3)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;x &amp;lt;- abs(x)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;m &amp;lt;- matrix(x, nrow = 4)&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
# パッケージをロードする。&lt;br /&gt;
# Load the package.&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;library(lattice)&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
# マージンゼロのテーマを定義する。参考サイトは&lt;a href=&quot;http://www.eml.ele.cst.nihon-u.ac.jp/~momma/wiki/wiki.cgi/R/lattice/%E3%83%9E%E3%83%BC%E3%82%B8%E3%83%B30%E3%81%AE%E3%83%97%E3%83%AD%E3%83%83%E3%83%88.html&quot; target=&quot;_blank&quot;&gt;こちら&lt;/a&gt;。&lt;br /&gt;
# Define the theme.&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;theme.x &amp;lt;- list(&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; layout.heights = list( &amp;nbsp;# マージンをゼロに&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;top.padding = 0,&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;main.key.padding = 0,&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;key.axis.padding = 0,&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;axis.xlab.padding = 0,&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;xlab.key.padding = 0,&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;key.sub.padding = 0,&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;bottom.padding = 0),&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;layout.widths = list(&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; left.padding = 0,&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; key.ylab.padding = 0,&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ylab.axis.padding = 0,&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; axis.key.padding = 0,&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; right.padding = 0&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;),&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; axis.line = list(lwd = 0) &amp;nbsp;# 外枠を消す&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; )&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
# 保存先に移動する。&lt;br /&gt;
# Change the working directory.&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;setwd(&quot;test&quot;)&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
# レベルプロットをPNGとして保存する。&lt;br /&gt;
# Draw a level plot and save it as a PNG.&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;width &amp;lt;- nrow(m)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;height &amp;lt;- ncol(m)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;filename &amp;lt;- &quot;m.png&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;png(filename = filename, width = width, height = height)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;levelplot(m, par.settings = theme.x, xlab = NULL, ylab = NULL,&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;scales = list(draw = FALSE), colorkey = FALSE)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;dev.off()&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiUQ4t_ACI49FUWWPSWhg4sTh1Tq4CeN38OCQMBleUcYYUtw7g_bepe6q9B2MxRJLDk6yk62qjELqdz2IXxd8QzByl0b9qz_RBr1nkbLmXUX2LbkUZcYrWP0ID7lq2bDfBRMQQmJ5BkVHKh/s1600/%25E3%2582%25B9%25E3%2582%25AF%25E3%2583%25AA%25E3%2583%25BC%25E3%2583%25B3%25E3%2582%25B7%25E3%2583%25A7%25E3%2583%2583%25E3%2583%2588+2016-07-20+16.36.08.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiUQ4t_ACI49FUWWPSWhg4sTh1Tq4CeN38OCQMBleUcYYUtw7g_bepe6q9B2MxRJLDk6yk62qjELqdz2IXxd8QzByl0b9qz_RBr1nkbLmXUX2LbkUZcYrWP0ID7lq2bDfBRMQQmJ5BkVHKh/s1600/%25E3%2582%25B9%25E3%2582%25AF%25E3%2583%25AA%25E3%2583%25BC%25E3%2583%25B3%25E3%2582%25B7%25E3%2583%25A7%25E3%2583%2583%25E3%2583%2588+2016-07-20+16.36.08.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
こうして得たPNGファイルは、X軸とY軸の表示もなく、色と値の関係も分からないが、１ピクセルに１つの値が入っているので取扱いやすい。&lt;br /&gt;
# The resulting PNG file does not have the XY-axises or colorkey. However, as it is completely in a pixel-based format, it may be good for some purposes.&lt;br /&gt;
&lt;br /&gt;
と、思いきや、Keynote ver. 6 以降に張り付けようとすると、PNGの画質が劣化する問題が生じる。この問題を回避するには、png()ではなくpdf()を使用するのが良さそう。pdf()は細い外枠が加えられるが、おそらく支障のないレベル。&lt;br /&gt;
&lt;br /&gt;
# レベルプロットをPDFとして保存する。&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;times&amp;quot; , &amp;quot;times new roman&amp;quot; , serif;&quot;&gt;# pdf()のサイズはピクセルではなくインチなので注意。&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;width &amp;lt;- nrow(m) / 72&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;height &amp;lt;- ncol(m) / 72&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;filename &amp;lt;- &quot;m.png&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;pdf(filename = filename, width = width, height = height)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;levelplot(m, par.settings = theme.x, xlab = NULL, ylab = NULL,&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;scales = list(draw = FALSE), colorkey = FALSE, useRaster = FALSE)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;dev.off()&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;pdf()&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;times&amp;quot; , &amp;quot;times new roman&amp;quot; , serif;&quot;&gt;を使うとき、&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;levelplot()&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;times&amp;quot; , &amp;quot;times new roman&amp;quot; , serif;&quot;&gt;に&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;useRaster=TRUE&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;times&amp;quot; , &amp;quot;times new roman&amp;quot; , serif;&quot;&gt;を与えると、keynoteに載せたときに絵が変になる。&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;times&amp;quot; , &amp;quot;times new roman&amp;quot; , serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhPRVtL866xv-FIHKOtugwa3QjpuxxvlanqP3mrHcm8PbQudpGqZEMSCu5S-hp_I10G4VSaUHObqw0gE5_PdBaLFgOI3lUnmovbROSxWg4SUsOaj91yF90RJgCL95KSYJhpaR_gvhGxWpU5/s1600/%25E5%2590%258D%25E7%25A7%25B0%25E6%259C%25AA%25E8%25A8%25AD%25E5%25AE%259A.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;156&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhPRVtL866xv-FIHKOtugwa3QjpuxxvlanqP3mrHcm8PbQudpGqZEMSCu5S-hp_I10G4VSaUHObqw0gE5_PdBaLFgOI3lUnmovbROSxWg4SUsOaj91yF90RJgCL95KSYJhpaR_gvhGxWpU5/s400/%25E5%2590%258D%25E7%25A7%25B0%25E6%259C%25AA%25E8%25A8%25AD%25E5%25AE%259A.jpg&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: &amp;quot;times&amp;quot; , &amp;quot;times new roman&amp;quot; , serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;times&amp;quot; , &amp;quot;times new roman&amp;quot; , serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;div id=&quot;UMS_TOOLTIP&quot; style=&quot;background-color: transparent; background-position: initial initial; background-repeat: initial initial; cursor: pointer; left: -100000px; position: absolute; top: -100000px; z-index: 2147483647;&quot;&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhd9JK8X0lMA6tEtRfFoSyXYhcMojbnG9vER84OhpsW9KbcRxjmRPwUj9ziNSGeCOcPSCDCjn90yz0QXJv397cVh3sjSFpheAHlayesKi08UI_NS2-jaAo4uYRzgWERuTYHCXVmK0Clizik/s1600/m.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhd9JK8X0lMA6tEtRfFoSyXYhcMojbnG9vER84OhpsW9KbcRxjmRPwUj9ziNSGeCOcPSCDCjn90yz0QXJv397cVh3sjSFpheAHlayesKi08UI_NS2-jaAo4uYRzgWERuTYHCXVmK0Clizik/s1600/m.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;img class=&quot;UMSRatingIcon&quot; id=&quot;ums_img_tooltip&quot; /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://bioinfomemoblog.blogspot.com/feeds/4351948132719348436/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='http://bioinfomemoblog.blogspot.com/2016/07/r-latticelevelplot_20.html#comment-form' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8963258932818536016/posts/default/4351948132719348436'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8963258932818536016/posts/default/4351948132719348436'/><link rel='alternate' type='text/html' href='http://bioinfomemoblog.blogspot.com/2016/07/r-latticelevelplot_20.html' title='R: latticeのlevelplot()で枠を消す'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiUQ4t_ACI49FUWWPSWhg4sTh1Tq4CeN38OCQMBleUcYYUtw7g_bepe6q9B2MxRJLDk6yk62qjELqdz2IXxd8QzByl0b9qz_RBr1nkbLmXUX2LbkUZcYrWP0ID7lq2bDfBRMQQmJ5BkVHKh/s72-c/%25E3%2582%25B9%25E3%2582%25AF%25E3%2583%25AA%25E3%2583%25BC%25E3%2583%25B3%25E3%2582%25B7%25E3%2583%25A7%25E3%2583%2583%25E3%2583%2588+2016-07-20+16.36.08.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8963258932818536016.post-7725977351114642024</id><published>2016-07-12T00:00:00.001+09:00</published><updated>2016-07-22T13:53:11.575+09:00</updated><title type='text'>R: strsplit() で、ピリオドを区切りとして文字列を分ける</title><content type='html'>strsplit()は、指定した文字を区切りとして文字列を分割する関数。&lt;br /&gt;
splitというArgumentで区切り文字を指定する。&lt;br /&gt;
&lt;br /&gt;
ピリオド「.」はワイルドカードとして認識されてしまう、というのが今回の問題。手元にピリオドを含む文字列があり、ピリオドを区切りとして２つの文字列に分割したいとき、エスケープする必要がある。&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# たとえば「ABC.01」という文字列を考える。&lt;br /&gt;
x &amp;lt;- &quot;ABC.01&quot;&lt;br /&gt;
&lt;br /&gt;
# ピリオドをそのまま与えると、ワイルドカードになる。&lt;br /&gt;
strsplit(x, split = &quot;.&quot;)[[1]]&lt;br /&gt;
&lt;br /&gt;
# 「\\」でエスケープすると、ピリオドが区切りとみなされる。&lt;br /&gt;
strsplit(x, split = &quot;\\.&quot;)[[1]]&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div id=&quot;UMS_TOOLTIP&quot; style=&quot;background-color: transparent; background-position: initial initial; background-repeat: initial initial; cursor: pointer; left: -100000px; position: absolute; top: -100000px; z-index: 2147483647;&quot;&gt;
&lt;img class=&quot;UMSRatingIcon&quot; id=&quot;ums_img_tooltip&quot; /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://bioinfomemoblog.blogspot.com/feeds/7725977351114642024/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='http://bioinfomemoblog.blogspot.com/2016/07/r-strsplit.html#comment-form' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8963258932818536016/posts/default/7725977351114642024'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8963258932818536016/posts/default/7725977351114642024'/><link rel='alternate' type='text/html' href='http://bioinfomemoblog.blogspot.com/2016/07/r-strsplit.html' title='R: strsplit() で、ピリオドを区切りとして文字列を分ける'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8963258932818536016.post-1332514230598913454</id><published>2016-07-12T00:00:00.000+09:00</published><updated>2016-07-22T13:26:58.882+09:00</updated><title type='text'>R: Map() でマップする</title><content type='html'>Map the values with Map().&lt;br /&gt;
&lt;br /&gt;
Map()はapply系の関数。mapply()のラッパー。&lt;br /&gt;
&lt;br /&gt;
Map()は沢山のArgumentsを受け付けてくれるのでとても便利。&lt;br /&gt;
マルチコア版のmcMap()もある。&lt;br /&gt;
&lt;br /&gt;
Map() is a wrapper function to mapply. Map() is useful as it takes lots of arguments. You can also use mcMap(), the multicore version of it.&lt;br /&gt;
&lt;br /&gt;
#######################################################&lt;br /&gt;
たとえば、以下のようなデータフレームがあるとする。&lt;br /&gt;
Assume that there is a data frame like this.&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;x &amp;lt;- data.frame(strA = c(&quot;A&quot;, &quot;B&quot;, &quot;C&quot;, &quot;D&quot;, &quot;E&quot;, &quot;F&quot;),&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;strB = c(&quot;a&quot;, &quot;b&quot;, &quot;c&quot;, &quot;d&quot;, &quot;e&quot;, &quot;f&quot;),&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;strC = c(&quot;1&quot;, &quot;2&quot;, &quot;3&quot;, &quot;4&quot;, &quot;5&quot;, &quot;6&quot;))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;gt; x&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;nbsp; strA strB strC&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;1 &amp;nbsp; &amp;nbsp;A &amp;nbsp; &amp;nbsp;a &amp;nbsp; &amp;nbsp;1&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;2 &amp;nbsp; &amp;nbsp;B &amp;nbsp; &amp;nbsp;b &amp;nbsp; &amp;nbsp;2&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;3 &amp;nbsp; &amp;nbsp;C &amp;nbsp; &amp;nbsp;c &amp;nbsp; &amp;nbsp;3&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;4 &amp;nbsp; &amp;nbsp;D &amp;nbsp; &amp;nbsp;d &amp;nbsp; &amp;nbsp;4&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;5 &amp;nbsp; &amp;nbsp;E &amp;nbsp; &amp;nbsp;e &amp;nbsp; &amp;nbsp;5&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;6 &amp;nbsp; &amp;nbsp;F &amp;nbsp; &amp;nbsp;f &amp;nbsp; &amp;nbsp;6&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
各row毎に、strAとstrBとstrCを繋げた文字列を得たいとする。&lt;br /&gt;
ついでに任意の文字（ここでは「-」）を加える。&lt;br /&gt;
And, you would like to concatenate character strings in the columns strA, strB and strC. Here, you may want the characters to be linked with &#39;-&#39;.&lt;br /&gt;
&lt;br /&gt;
当然ながら、for()ループで実現できる。&lt;br /&gt;
You can do it with the for().&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;x$strABC &amp;lt;- &quot;&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;for(i in 1:nrow(x)){&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;strABC &amp;lt;- paste(x$strA[i], x$strB[i], x$strC[i], sep = &quot;-&quot;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;x$strABC[i] &amp;lt;- strABC&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
for()ループの結果。&lt;br /&gt;
The result of the for loop.&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;gt; x&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;nbsp; strA strB strC strABC&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;1 &amp;nbsp; &amp;nbsp;A &amp;nbsp; &amp;nbsp;a &amp;nbsp; &amp;nbsp;1 &amp;nbsp;A-a-1&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;2 &amp;nbsp; &amp;nbsp;B &amp;nbsp; &amp;nbsp;b &amp;nbsp; &amp;nbsp;2 &amp;nbsp;B-b-2&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;3 &amp;nbsp; &amp;nbsp;C &amp;nbsp; &amp;nbsp;c &amp;nbsp; &amp;nbsp;3 &amp;nbsp;C-c-3&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;4 &amp;nbsp; &amp;nbsp;D &amp;nbsp; &amp;nbsp;d &amp;nbsp; &amp;nbsp;4 &amp;nbsp;D-d-4&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;5 &amp;nbsp; &amp;nbsp;E &amp;nbsp; &amp;nbsp;e &amp;nbsp; &amp;nbsp;5 &amp;nbsp;E-e-5&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;6 &amp;nbsp; &amp;nbsp;F &amp;nbsp; &amp;nbsp;f &amp;nbsp; &amp;nbsp;6 &amp;nbsp;F-f-6&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
しかし、rowの数が増えるほど計算が遅くなってしまう。Map()だと速い。&lt;br /&gt;
However, the more row numbers you have, the more time it takes. Map() does this more rapidly.&lt;br /&gt;
&lt;br /&gt;
Map()を使うには、まず関数をつくる必要がある。&lt;br /&gt;
In order to use Map(), you need to make a function to be used by the function Map().&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;get.strABC &amp;lt;- function(strA, strB, strC){&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;return(paste(strA, strB, strC, sep = &quot;-&quot;))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
この関数を使ってみるとこんな結果が帰ってくる。&lt;br /&gt;
This function acts like this.&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;gt; get.strABC(&quot;A&quot;, &quot;a&quot;, &quot;1&quot;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;[1] &quot;A-a-1&quot;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
上のfor()ループの中でこの関数を使うと同じ結果を得ることができる。&lt;br /&gt;
Of course, you can use this function in a for loop.&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;x$strABC &amp;lt;- &quot;&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;for(i in 1:nrow(x)){&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;x$strABC[i] &amp;lt;- get.strABC(x$strA[i], x$strB[i], x$strC[i])&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Map()でget.strABC()を実行する。Map()はリストで結果を返すので、unlist()で結果をシンプルにする必要がある。&lt;br /&gt;
Let&#39;s use Map(). You need to unlist the output of Map() to map the values in a preexisting container.&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;x$strABC &amp;lt;- unlist(Map(f = get.strABC,&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;strA = x$strA,&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;strB = x$strB,&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;strC = x$strC))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;gt; x&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;nbsp; strA strB strC strABC&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;1 &amp;nbsp; &amp;nbsp;A &amp;nbsp; &amp;nbsp;a &amp;nbsp; &amp;nbsp;1 &amp;nbsp;A-a-1&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;2 &amp;nbsp; &amp;nbsp;B &amp;nbsp; &amp;nbsp;b &amp;nbsp; &amp;nbsp;2 &amp;nbsp;B-b-2&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;3 &amp;nbsp; &amp;nbsp;C &amp;nbsp; &amp;nbsp;c &amp;nbsp; &amp;nbsp;3 &amp;nbsp;C-c-3&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;4 &amp;nbsp; &amp;nbsp;D &amp;nbsp; &amp;nbsp;d &amp;nbsp; &amp;nbsp;4 &amp;nbsp;D-d-4&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;5 &amp;nbsp; &amp;nbsp;E &amp;nbsp; &amp;nbsp;e &amp;nbsp; &amp;nbsp;5 &amp;nbsp;E-e-5&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;6 &amp;nbsp; &amp;nbsp;F &amp;nbsp; &amp;nbsp;f &amp;nbsp; &amp;nbsp;6 &amp;nbsp;F-f-6&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Map()のマルチコア版であるmcMap()も使える。この場合、parallelパッケージをロードする必要がある。&lt;br /&gt;
You can also use mcMap(), which is the multicore version of Map().&lt;br /&gt;
You need load the parallel package to do it.&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;library(parallel)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;x$strABC &amp;lt;- unlist(mcMap(f = get.strABC,&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;strA = x$strA,&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;strB = x$strB,&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;strC = x$strC))&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
mcMap()のArgumentであるmc.coresで、使うコアの数を制御できる。&lt;br /&gt;
The number of cores can be regulated with the argument mc.cores.&lt;br /&gt;
&lt;br /&gt;
#######################################################&lt;br /&gt;
rowの数を増やしてfor()とMap()を比べる。&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;x &amp;lt;- data.frame(strA = c(&quot;A&quot;, &quot;B&quot;, &quot;C&quot;, &quot;D&quot;, &quot;E&quot;, &quot;F&quot;),&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;strB = c(&quot;a&quot;, &quot;b&quot;, &quot;c&quot;, &quot;d&quot;, &quot;e&quot;, &quot;f&quot;),&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;strC = c(&quot;1&quot;, &quot;2&quot;, &quot;3&quot;, &quot;4&quot;, &quot;5&quot;, &quot;6&quot;))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;for(i in 1:12) x &amp;lt;- rbind(x, x)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;gt; nrow(x)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;[1] 24576&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
for()ループでやると、4.286秒かかる。&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;x$strABC &amp;lt;- &quot;&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;system.time(&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;for(i in 1:nrow(x)){&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;x$strABC[i] &amp;lt;- get.strABC(x$strA[i], x$strB[i], x$strC[i])&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;nbsp; &amp;nbsp;ユーザ &amp;nbsp; システム &amp;nbsp; &amp;nbsp; &amp;nbsp; 経過 &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;4.169 &amp;nbsp; &amp;nbsp; &amp;nbsp;0.137 &amp;nbsp; &amp;nbsp; &amp;nbsp;4.286&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Map()でやると、0.940秒。for()より速い。&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;system.time(&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;x$strABC &amp;lt;- unlist(Map(f = get.strABC,&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;strA = x$strA,&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;strB = x$strB,&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;strC = x$strC))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;nbsp; &amp;nbsp;ユーザ &amp;nbsp; システム &amp;nbsp; &amp;nbsp; &amp;nbsp; 経過 &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;0.892 &amp;nbsp; &amp;nbsp; &amp;nbsp;0.009 &amp;nbsp; &amp;nbsp; &amp;nbsp;0.940&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
mcMap()でやると、0.711秒。Map()との差は小さい。&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;system.time(&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;x$strABC &amp;lt;- unlist(mcMap(f = get.strABC,&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;strA = x$strA,&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;strB = x$strB,&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;strC = x$strC, mc.cores = 4))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;nbsp; &amp;nbsp;ユーザ &amp;nbsp; システム &amp;nbsp; &amp;nbsp; &amp;nbsp; 経過 &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;1.697 &amp;nbsp; &amp;nbsp; &amp;nbsp;0.155 &amp;nbsp; &amp;nbsp; &amp;nbsp;0.711&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#######################################################&lt;br /&gt;
rowの数を増やしてMap()とmcMap()を比べる。&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;x &amp;lt;- data.frame(strA = c(&quot;A&quot;, &quot;B&quot;, &quot;C&quot;, &quot;D&quot;, &quot;E&quot;, &quot;F&quot;),&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;strB = c(&quot;a&quot;, &quot;b&quot;, &quot;c&quot;, &quot;d&quot;, &quot;e&quot;, &quot;f&quot;),&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;strC = c(&quot;1&quot;, &quot;2&quot;, &quot;3&quot;, &quot;4&quot;, &quot;5&quot;, &quot;6&quot;))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;for(i in 1:16) x &amp;lt;- rbind(x, x)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;gt; nrow(x)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;[1] 393216&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Map()でやると、16.926秒かかる。for()は怖くて試せない。&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;system.time(&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;x$strABC &amp;lt;- unlist(Map(f = get.strABC,&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;strA = x$strA,&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;strB = x$strB,&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;strC = x$strC))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;nbsp; &amp;nbsp;ユーザ &amp;nbsp; システム &amp;nbsp; &amp;nbsp; &amp;nbsp; 経過 &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; 16.596 &amp;nbsp; &amp;nbsp; &amp;nbsp;0.107 &amp;nbsp; &amp;nbsp; 16.926&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
mcMap(mc.cores = 4)でやると、8.939秒。Map()の半分の時間。&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;system.time(&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;x$strABC &amp;lt;- unlist(mcMap(f = get.strABC,&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;strA = x$strA,&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;strB = x$strB,&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;strC = x$strC, mc.cores = 4))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;nbsp; &amp;nbsp;ユーザ &amp;nbsp; システム &amp;nbsp; &amp;nbsp; &amp;nbsp; 経過 &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;1.104 &amp;nbsp; &amp;nbsp; &amp;nbsp;0.172 &amp;nbsp; &amp;nbsp; &amp;nbsp;8.939&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
mcMap(mc.cores = 20)でやると、3.412秒。かなり速い。&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;system.time(&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;x$strABC &amp;lt;- unlist(mcMap(f = get.strABC,&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;strA = x$strA,&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;strB = x$strB,&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;strC = x$strC, mc.cores = 20))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;nbsp; &amp;nbsp;ユーザ &amp;nbsp; システム &amp;nbsp; &amp;nbsp; &amp;nbsp; 経過 &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; 80.537 &amp;nbsp; &amp;nbsp; &amp;nbsp;3.933 &amp;nbsp; &amp;nbsp; &amp;nbsp;3.412&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div id=&quot;UMS_TOOLTIP&quot; style=&quot;background-color: transparent; background-position: initial initial; background-repeat: initial initial; cursor: pointer; left: -100000px; position: absolute; top: -100000px; z-index: 2147483647;&quot;&gt;
&lt;img class=&quot;UMSRatingIcon&quot; id=&quot;ums_img_tooltip&quot; /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://bioinfomemoblog.blogspot.com/feeds/1332514230598913454/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='http://bioinfomemoblog.blogspot.com/2016/07/r-map.html#comment-form' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8963258932818536016/posts/default/1332514230598913454'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8963258932818536016/posts/default/1332514230598913454'/><link rel='alternate' type='text/html' href='http://bioinfomemoblog.blogspot.com/2016/07/r-map.html' title='R: Map() でマップする'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8963258932818536016.post-4014849553948832810</id><published>2016-07-07T00:00:00.000+09:00</published><updated>2017-03-10T09:52:35.505+09:00</updated><title type='text'>R: read.table() EOFの警告</title><content type='html'>read.table()で以下のような警告が出る場合、read.table()に「quote = &quot;&quot;」を与えると、とりあえず警告が消える。&lt;br /&gt;
When you are using the function read.table() and encounter the warnings like below, just give &#39;quote = &quot;&quot;&#39; to the read.talbe() to avoid the problem.&lt;br /&gt;
&lt;br /&gt;
【日本語の警告】&lt;br /&gt;
&amp;nbsp;警告メッセージ:&lt;br /&gt;
&amp;nbsp;scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings, &amp;nbsp;で:&lt;br /&gt;
&amp;nbsp; &amp;nbsp;クオートで囲まれた文字列中にEOFがあります&lt;br /&gt;
&lt;br /&gt;
【Warning in English】&lt;br /&gt;
Warning message:In scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings, &amp;nbsp;:&lt;br /&gt;
EOF within quoted string&lt;br /&gt;
&lt;br /&gt;
上は、「&quot;」や「&#39;」が悪さをしているときの解決法になります。&lt;br /&gt;
&lt;br /&gt;
もともと &quot;\&quot;&#39;&quot; がデフォルトなので、 取り込み対象の書類に２カ所のダブルクォートあるいはシングルクォートがあると、警告なしに、一見問題なく取り込まれます。&lt;br /&gt;
&lt;br /&gt;
異なる２つの行に個別に奇数のクォートがあると、その間の行はトリミングされます。しかも恐ろしいことに、警告がでません。&lt;br /&gt;
&lt;br /&gt;
EOF のメッセージが出るのは、たまたま奇数のクォートが奇数行に存在するときだけらしいです。&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div id=&quot;UMS_TOOLTIP&quot; style=&quot;background-color: transparent; background-position: initial initial; background-repeat: initial initial; cursor: pointer; left: -100000px; position: absolute; top: -100000px; z-index: 2147483647;&quot;&gt;
&lt;img class=&quot;UMSRatingIcon&quot; id=&quot;ums_img_tooltip&quot; /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://bioinfomemoblog.blogspot.com/feeds/4014849553948832810/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='http://bioinfomemoblog.blogspot.com/2016/07/r-readtable-eof.html#comment-form' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8963258932818536016/posts/default/4014849553948832810'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8963258932818536016/posts/default/4014849553948832810'/><link rel='alternate' type='text/html' href='http://bioinfomemoblog.blogspot.com/2016/07/r-readtable-eof.html' title='R: read.table() EOFの警告'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8963258932818536016.post-218493903014305726</id><published>2016-05-27T00:00:00.000+09:00</published><updated>2016-07-22T13:52:45.507+09:00</updated><title type='text'>R：文字列をつなぐ</title><content type='html'>Rで文字を繋ぐためにはpaste()を使う。&lt;br /&gt;
You can concatenate character strings with the function paste().&lt;br /&gt;
&lt;br /&gt;
ひとつの文字列ベクターに含まれる各文字列を繋いで１つにしたいとき、collapseを使うと良い。&lt;br /&gt;
If you want to concatenate the strings in a character vector to obtain one string in which all the strings in the vector are linked together, use the argument collapse.&lt;br /&gt;
&lt;br /&gt;
x &amp;lt;- &quot;ABC&quot;&lt;br /&gt;
y &amp;lt;- &quot;DEF&quot;&lt;br /&gt;
z &amp;lt;- c(x, y)&lt;br /&gt;
&lt;br /&gt;
# zには２つの文字列が入っている。&lt;br /&gt;
# There are two strings in the character vector z.&lt;br /&gt;
# &amp;gt; z&lt;br /&gt;
# [1] &quot;ABC&quot; &quot;DEF&quot;&lt;br /&gt;
&lt;br /&gt;
# collapseを使わないとき、文字列は２つのまま、文字列が繋がる。&lt;br /&gt;
# When you use paste() without the collapse argument, the resultant object will contain two strings.&lt;br /&gt;
# &amp;gt; paste(z, sep = &quot;&quot;)&lt;br /&gt;
# [1] &quot;ABC&quot; &quot;DEF&quot;&lt;br /&gt;
&lt;br /&gt;
# collapseを使うと、文字列が１つにまとまる。&lt;br /&gt;
# If you use the collapse, the strings will be linked together.&lt;br /&gt;
# &amp;gt; paste(z, sep = &quot;&quot;, collapse = &quot;&quot;)&lt;br /&gt;
# [1] &quot;ABCDEF&quot;&lt;br /&gt;
&lt;br /&gt;
# つなぎを指定することもできる。&lt;br /&gt;
# You can add your favorite characters in between the strings.&lt;br /&gt;
# &amp;gt; paste(z, sep = &quot;&quot;, collapse = &quot;*&quot;)&lt;br /&gt;
# [1] &quot;ABC*DEF&quot;&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div id=&quot;UMS_TOOLTIP&quot; style=&quot;background-color: transparent; background-position: initial initial; background-repeat: initial initial; cursor: pointer; left: -100000px; position: absolute; top: -100000px; z-index: 2147483647;&quot;&gt;
&lt;img class=&quot;UMSRatingIcon&quot; id=&quot;ums_img_tooltip&quot; /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://bioinfomemoblog.blogspot.com/feeds/218493903014305726/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='http://bioinfomemoblog.blogspot.com/2016/05/r.html#comment-form' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8963258932818536016/posts/default/218493903014305726'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8963258932818536016/posts/default/218493903014305726'/><link rel='alternate' type='text/html' href='http://bioinfomemoblog.blogspot.com/2016/05/r.html' title='R：文字列をつなぐ'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8963258932818536016.post-3813419992141995709</id><published>2016-04-21T00:00:00.000+09:00</published><updated>2016-07-22T13:54:04.308+09:00</updated><title type='text'>Fortranにやってもらう</title><content type='html'>Rをある程度習熟すれば、考えたことをなんでも実行できる。塩基配列の取扱いはBiostringsパッケージが強力だし、parallelパッケージの並列処理で多くの作業を高速化できる。&lt;br /&gt;
&lt;br /&gt;
だけれども、やりたい計算があまりにもマニアックでapply系が使えないとき、とても困る。for()を多用せざるをえないような計算だ。&lt;br /&gt;
&lt;br /&gt;
一応、for()も高速化はできる。先に適切なオブジェクトをつくっておき、その中のある座標だけを入れ替えるようにfor()ループを組み立てておけば、それなりに速く計算が終わる。宣言する感じ。そのつどオブジェクトを作り直すように組み立ててしまうと極端に遅い。それに、巨大なデータを用いて計算すると、速いといっても大したことない。&lt;br /&gt;
&lt;br /&gt;
そこでFortranの出番となる。&lt;br /&gt;
&lt;br /&gt;
RとFortranをつなぐのは.Fortran()という関数。Fortranのコードはプログラムではなくサブルーチンとして用意する。RからFortranに変数を渡せるし、FortranからRに変数を返してもらえる。ただし、サブルーチンの記述通りの順番で変数を渡す必要があるし、渡した変数しか返してもらえない。&lt;br /&gt;
&lt;br /&gt;
サブルーチンの最後まで行った時点で保持していた変数のうち、Rから受け取ったものと同じもののみが、Rに帰ってくる。リストとして束ねられている。Fortranサイドで得た計算結果を受け取るためには、あらかじめRから初期値を入れた変数を与えて、それをFortranサイドで上書きしてしまえば良い。&lt;br /&gt;
&lt;br /&gt;
RからFortranに変数が渡されると、Fortranが計算する。Fortranから変数が戻ってくるとき、Rのオブジェクトの中身だけを入れ替える形で戻ってくるらしい。だから、Fortranサイドでの宣言の仕方によってはおかしなことになる。&lt;br /&gt;
&lt;br /&gt;
たとえば character(3) x みたいな感じで３個しか文字を格納できないようにしていると、Rから「x = &quot;ABCDE&quot;」というふうに５文字を受け取ったとしても Fortranで使うのは最初の３文字だけとなる（&quot;ABC&quot;）。この３文字を仮に別の文字に入れ替えてみるとする。たとえば、「x(3:3) = &#39;a&#39;」とすると&quot;ABa&quot;になるのだが、このxをRに返してやると、上書きで返すのでRが受け取る変数は最初の３文字だけが改変された５文字、つまり&quot;ABaDE&quot;ということになる。&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div id=&quot;UMS_TOOLTIP&quot; style=&quot;background-color: transparent; background-position: initial initial; background-repeat: initial initial; cursor: pointer; left: -100000px; position: absolute; top: -100000px; z-index: 2147483647;&quot;&gt;
&lt;img class=&quot;UMSRatingIcon&quot; id=&quot;ums_img_tooltip&quot; /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://bioinfomemoblog.blogspot.com/feeds/3813419992141995709/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='http://bioinfomemoblog.blogspot.com/2016/04/fortran.html#comment-form' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8963258932818536016/posts/default/3813419992141995709'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8963258932818536016/posts/default/3813419992141995709'/><link rel='alternate' type='text/html' href='http://bioinfomemoblog.blogspot.com/2016/04/fortran.html' title='Fortranにやってもらう'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8963258932818536016.post-4354558252790424621</id><published>2016-04-01T00:00:00.000+09:00</published><updated>2016-07-22T13:54:14.966+09:00</updated><title type='text'>数字の並びを部分的に置換したいとき</title><content type='html'>数字の並びを部分的に置換することを考える。&lt;br /&gt;
&lt;br /&gt;
たとえば、あるinteger vectorの中に存在する「3, 4, 5」を「5, 4, 3」に置き換えたいとき。&lt;br /&gt;
ここでは、文字列用の関数であるpaste()とgsub()を使ったトリックを紹介する。&lt;br /&gt;
&lt;br /&gt;
適当なinteger vectorを作る。&lt;br /&gt;
int &amp;lt;- 0:9&lt;br /&gt;
int.vec &amp;lt;- c(int, int, int)&lt;br /&gt;
&lt;br /&gt;
&amp;gt; int.vec&lt;br /&gt;
&amp;nbsp;[1] 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
【for()ループでやる場合】&lt;br /&gt;
&lt;br /&gt;
int.vec.new &amp;lt;- int.vec&lt;br /&gt;
for(i in 1:length(int.vec)){&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;if(int.vec[i] == 3 &amp;amp; int.vec[i+1] == 4 &amp;amp; int.vec[i+2] == 5){&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;int.vec.new[i:(i+2)] &amp;lt;- c(5, 4, 3)&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;i &amp;lt;- i + 2&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;gt; int.vec.new&lt;br /&gt;
&amp;nbsp;[1] 0 1 2 5 4 3 6 7 8 9 0 1 2 5 4 3 6 7 8 9 0 1 2 5 4 3 6 7 8 9&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
int.vecの中の「3, 4, 5」を「5, 4, 3」に置き換える仕事をfor()ループでやろうとすると、&lt;br /&gt;
このように一応はできるのだけれども、for()ループは遅い。&lt;br /&gt;
とくにvectorが長いほど遅さを実感する。&lt;br /&gt;
&lt;br /&gt;
そこで、paste()とgsub()を使ったトリックの登場。&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
【paste()とgsub()でやる場合】&lt;br /&gt;
&lt;br /&gt;
chr.vec &amp;lt;- paste(int.vec, sep = &quot;&quot;, collapse = &quot;&quot;)&lt;br /&gt;
int.vec.new &amp;lt;- as.integer(strsplit(gsub(&quot;345&quot;, &quot;543&quot;, chr.vec), split = &quot;&quot;)[[1]])&lt;br /&gt;
&lt;br /&gt;
&amp;gt; int.vec.new&lt;br /&gt;
&amp;nbsp;[1] 0 1 2 5 4 3 6 7 8 9 0 1 2 5 4 3 6 7 8 9 0 1 2 5 4 3 6 7 8 9&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
まず、int.vecの値を文字列として繋げてしまう。&lt;br /&gt;
paste() はintegerを与えられたとしても、それをcharacterとして扱う。&lt;br /&gt;
collapseをうまく使えばすべての文字が繋がって、値がひとつのcharacter vectorになる。&lt;br /&gt;
&lt;br /&gt;
chr.vec &amp;lt;- paste(int.vec, sep = &quot;&quot;, collapse = &quot;&quot;)&lt;br /&gt;
&lt;br /&gt;
&amp;gt; chr.vec&lt;br /&gt;
[1] &quot;012345678901234567890123456789&quot;&lt;br /&gt;
&lt;br /&gt;
こうしてひとつなぎの文字列にしてしまえば、gsub()が使える。&lt;br /&gt;
sub()は１つ目のヒットだけを置換するが、gsub()はすべてのヒットを置換する。&lt;br /&gt;
&lt;br /&gt;
gsub(&quot;345&quot;, &quot;543&quot;, chr.vec)&lt;br /&gt;
&lt;br /&gt;
&amp;gt; gsub(&quot;345&quot;, &quot;543&quot;, chr.vec)&lt;br /&gt;
[1] &quot;012543678901254367890125436789&quot;&lt;br /&gt;
&lt;br /&gt;
あとは、strsplit()で１文字ずつ切り出し、integerに戻す。&lt;br /&gt;
strsplit() はリストで返すので、その１つ目を採用する。&lt;br /&gt;
&lt;br /&gt;
&amp;gt; strsplit(gsub(&quot;345&quot;, &quot;543&quot;, chr.vec), split = &quot;&quot;)&lt;br /&gt;
[[1]]&lt;br /&gt;
&amp;nbsp;[1] &quot;0&quot; &quot;1&quot; &quot;2&quot; &quot;5&quot; &quot;4&quot; &quot;3&quot; &quot;6&quot; &quot;7&quot; &quot;8&quot; &quot;9&quot; &quot;0&quot; &quot;1&quot; &quot;2&quot; &quot;5&quot; &quot;4&quot; &quot;3&quot; &quot;6&quot; &quot;7&quot; &quot;8&quot;&lt;br /&gt;
[20] &quot;9&quot; &quot;0&quot; &quot;1&quot; &quot;2&quot; &quot;5&quot; &quot;4&quot; &quot;3&quot; &quot;6&quot; &quot;7&quot; &quot;8&quot; &quot;9&quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
回りくどい仕事のように見えるが、対象が大きくなるほど早さを実感する。&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div id=&quot;UMS_TOOLTIP&quot; style=&quot;background-color: transparent; background-position: initial initial; background-repeat: initial initial; cursor: pointer; left: -100000px; position: absolute; top: -100000px; z-index: 2147483647;&quot;&gt;
&lt;img class=&quot;UMSRatingIcon&quot; id=&quot;ums_img_tooltip&quot; /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://bioinfomemoblog.blogspot.com/feeds/4354558252790424621/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='http://bioinfomemoblog.blogspot.com/2016/04/blog-post.html#comment-form' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8963258932818536016/posts/default/4354558252790424621'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8963258932818536016/posts/default/4354558252790424621'/><link rel='alternate' type='text/html' href='http://bioinfomemoblog.blogspot.com/2016/04/blog-post.html' title='数字の並びを部分的に置換したいとき'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8963258932818536016.post-7220354245821826413</id><published>2016-03-22T00:00:00.000+09:00</published><updated>2016-07-30T12:18:27.469+09:00</updated><title type='text'>あるドメインをもつタンパク質をコードする遺伝子の数</title><content type='html'>興味のあるドメインがあるとして、そのドメインをもつタンパク質がヒトゲノムにどれだけコードされているかを調査する方法のメモ。&lt;br /&gt;
&lt;br /&gt;
例えば、HMGというドメイン。このドメインの「SMART ID」は「SM00398」。&lt;br /&gt;
http://smart.embl.de/smart/do_annotation.pl?BLAST=DUMMY&amp;amp;DOMAIN=SM00398&lt;br /&gt;
&lt;br /&gt;
ポイントは「SMART MODE」を「GENOMIC」にしておくこと。&lt;br /&gt;
SMARTのサイトのEvolutionという項目をたどればヒトにいくつのタンパク質があるかわかる。&lt;br /&gt;
「SMART MODE」が「NORMAL」だと147。&lt;br /&gt;
「SMART MODE」が「GENOMIC」だと37。&lt;br /&gt;
&lt;br /&gt;
この37の数字をクリックして「Expand all nodes」をクリックするとすべての候補の名前を確認することができる。&lt;br /&gt;
でも、「ENSP...」というEnsemblのIDが付与されたものや、「..._HUMAN」という感じで遺伝子名が付与されたものや、UniprotのIDが付与されたものが混在している。だから、結局のところ現行ゲノムにどれだけ遺伝子が存在するのかよくわからない。そもそも「GENOMIC」での絞り込みが妥当かどうかがよくわからない。&lt;br /&gt;
&lt;br /&gt;
この問題を回避するため、EnsemblのBiomartを使う。&lt;br /&gt;
http://www.ensembl.org/biomart/martview&lt;br /&gt;
&lt;br /&gt;
セッティングは以下のとおり。&lt;br /&gt;
Dataset:&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;CHOOSE DATABASE:&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;Ensembl Genes 84&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;CHOOSE DATASET:&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;Homo sapience genes (GRCh38.p5)&lt;br /&gt;
Filters:&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;PROTEIN DOMAINS AND FAMILIES&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;Limit to genes with these family or domain IDs&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;SMART ID(s):&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;SM00398&lt;br /&gt;
Attributes:&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;Features&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;GENE: Associated Gene Name, Description&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;PROTEIN DOMAINS AND FAMILIES: Domains: SMART ID&lt;br /&gt;
&lt;br /&gt;
ポイントは、Ensemble Gene IDなどを呼び出さないこと。これをやっちゃうと変なものまで出てくる。&lt;br /&gt;
Countすると、52件のヒット。&lt;br /&gt;
Resultsの「Unique results only」で限定してダウンロードすると、52遺伝子の情報を得ることができる。&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
こうすれば、特定のSMART IDをもつ遺伝子が現行ゲノムにいくつあるかを知ることができる。&lt;br /&gt;
Transcript variantがやたらとあるので遺伝子単位で数を数えるのが妥当だと思う。&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div id=&quot;UMS_TOOLTIP&quot; style=&quot;background-color: transparent; background-position: initial initial; background-repeat: initial initial; cursor: pointer; left: -100000px; position: absolute; top: -100000px; z-index: 2147483647;&quot;&gt;
&lt;img class=&quot;UMSRatingIcon&quot; id=&quot;ums_img_tooltip&quot; /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://bioinfomemoblog.blogspot.com/feeds/7220354245821826413/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='http://bioinfomemoblog.blogspot.com/2016/03/blog-post.html#comment-form' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8963258932818536016/posts/default/7220354245821826413'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8963258932818536016/posts/default/7220354245821826413'/><link rel='alternate' type='text/html' href='http://bioinfomemoblog.blogspot.com/2016/03/blog-post.html' title='あるドメインをもつタンパク質をコードする遺伝子の数'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8963258932818536016.post-9098144085041744776</id><published>2013-08-28T01:04:00.000+09:00</published><updated>2013-08-28T01:04:25.227+09:00</updated><title type='text'>R: new.env() で環境をつくる</title><content type='html'>CRAN のポリシーのひとつに、大局的環境（.GlobalEnv）を操作してはならない、というのがある。自作パッケージの関数の中でオブジェクトを&amp;nbsp;.GlobalEnv に assgin() したり、そこから get() していたので、このポリシーの存在には正直へこんだ。少なくとも、最終段階で気づくべきことではない。&lt;br /&gt;
&lt;br /&gt;
google 先生に色々訊ねた結果、どうやらこの道の常識では .GlobalEnv は綺麗にしておくものらしい。&lt;br /&gt;
&lt;br /&gt;
ポリシーに従ったパッケージにするためには、パッケージの環境に new.env() で小環境を作れば良い。たとえば、DATA という環境をつくる。そして、パッケージの中の assign(pos = .GlobalEnv) や get (pos = .GlobalEnv) を、assign(pos = DATA) や get(pos = DATA) に置換すればうまくいくはず。&lt;br /&gt;
&lt;br /&gt;
以下のコードを R コンソールにコピペして、各関数を実行してみたら理解しやすいと思う。ls() で調べれば、.GlobalEnv の中に小環境 DATA が作られるのがわかる。ls(DATA) で 小環境 DATA の中のオブジェクトを確認できる。&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;color: #4f4f4f; font-family: Monaco; font-size: 11px; margin-left: 4px; text-indent: -4px;&quot;&gt;
# create an environment named DATA.&lt;/div&gt;
&lt;div style=&quot;color: #1a1599; font-family: Monaco; font-size: 11px; margin-left: 4px; text-indent: -4px;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;DATA&lt;/span&gt; &amp;lt;- new.env(&lt;span style=&quot;color: black;&quot;&gt;parent&lt;/span&gt; = emptyenv())&lt;/div&gt;
&lt;div style=&quot;color: #1a1599; font-family: Monaco; font-size: 11px; margin-left: 4px; min-height: 15px; text-indent: -4px;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;color: #4f4f4f; font-family: Monaco; font-size: 11px; margin-left: 4px; text-indent: -4px;&quot;&gt;
# assign an object to DATA.&lt;/div&gt;
&lt;div style=&quot;font-family: Monaco; font-size: 11px; margin-left: 4px; text-indent: -4px;&quot;&gt;
assignToDATA &lt;span style=&quot;color: #1a1599;&quot;&gt;&amp;lt;- &lt;/span&gt;&lt;span style=&quot;color: #c38907;&quot;&gt;function&lt;/span&gt; &lt;span style=&quot;color: #1a1599;&quot;&gt;(&lt;/span&gt;name &lt;span style=&quot;color: #1a1599;&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: #b01301;&quot;&gt;&quot;unknown&quot;&lt;/span&gt;&lt;span style=&quot;color: #1a1599;&quot;&gt;, &lt;/span&gt;value &lt;span style=&quot;color: #1a1599;&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: #b01301;&quot;&gt;&quot;unknown&quot;&lt;/span&gt;&lt;span style=&quot;color: #1a1599;&quot;&gt;){&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Monaco; font-size: 11px; margin-left: 4px; text-indent: -4px;&quot;&gt;
&lt;span style=&quot;color: #1a1599;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;assign(&lt;/span&gt;name&lt;span style=&quot;color: #1a1599;&quot;&gt;,&lt;/span&gt; value&lt;span style=&quot;color: #1a1599;&quot;&gt;,&lt;/span&gt; pos &lt;span style=&quot;color: #1a1599;&quot;&gt;=&lt;/span&gt; DATA&lt;span style=&quot;color: #1a1599;&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #1a1599; font-family: Monaco; font-size: 11px; margin-left: 4px; text-indent: -4px;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;color: #1a1599; font-family: Monaco; font-size: 11px; margin-left: 4px; min-height: 15px; text-indent: -4px;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;color: #4f4f4f; font-family: Monaco; font-size: 11px; margin-left: 4px; text-indent: -4px;&quot;&gt;
# get an object from DATA.&lt;/div&gt;
&lt;div style=&quot;font-family: Monaco; font-size: 11px; margin-left: 4px; text-indent: -4px;&quot;&gt;
getFromDATA &lt;span style=&quot;color: #1a1599;&quot;&gt;&amp;lt;- &lt;/span&gt;&lt;span style=&quot;color: #c38907;&quot;&gt;function&lt;/span&gt; &lt;span style=&quot;color: #1a1599;&quot;&gt;(&lt;/span&gt;name &lt;span style=&quot;color: #1a1599;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #b01301;&quot;&gt;&quot;unknown&quot;&lt;/span&gt;&lt;span style=&quot;color: #1a1599;&quot;&gt;){&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Monaco; font-size: 11px; margin-left: 4px; text-indent: -4px;&quot;&gt;
&lt;span style=&quot;color: #1a1599;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;get(&lt;/span&gt;name&lt;span style=&quot;color: #1a1599;&quot;&gt;,&lt;/span&gt; pos &lt;span style=&quot;color: #1a1599;&quot;&gt;=&lt;/span&gt; DATA&lt;span style=&quot;color: #1a1599;&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #1a1599; font-family: Monaco; font-size: 11px; margin-left: 4px; text-indent: -4px;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;color: #1a1599; font-family: Monaco; font-size: 11px; margin-left: 4px; min-height: 15px; text-indent: -4px;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;color: #4f4f4f; font-family: Monaco; font-size: 11px; margin-left: 4px; text-indent: -4px;&quot;&gt;
# remove an object from DATA.&lt;/div&gt;
&lt;div style=&quot;font-family: Monaco; font-size: 11px; margin-left: 4px; text-indent: -4px;&quot;&gt;
rmFromDATA &lt;span style=&quot;color: #1a1599;&quot;&gt;&amp;lt;- &lt;/span&gt;&lt;span style=&quot;color: #c38907;&quot;&gt;function&lt;/span&gt; &lt;span style=&quot;color: #1a1599;&quot;&gt;(&lt;/span&gt;list&lt;span style=&quot;color: #1a1599;&quot;&gt; = &lt;/span&gt;&lt;span style=&quot;color: #b01301;&quot;&gt;&quot;unknown&quot;&lt;/span&gt;&lt;span style=&quot;color: #1a1599;&quot;&gt;){&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Monaco; font-size: 11px; margin-left: 4px; text-indent: -4px;&quot;&gt;
&lt;span style=&quot;color: #1a1599;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;rm(&lt;/span&gt;list &lt;span style=&quot;color: #1a1599;&quot;&gt;=&lt;/span&gt; list&lt;span style=&quot;color: #1a1599;&quot;&gt;,&lt;/span&gt; pos &lt;span style=&quot;color: #1a1599;&quot;&gt;=&lt;/span&gt; DATA&lt;span style=&quot;color: #1a1599;&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #1a1599; font-family: Monaco; font-size: 11px; margin-left: 4px; text-indent: -4px;&quot;&gt;
}&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
パッケージの「R」ディレクトリに入れる「.r」ファイルの１つに 「DATA &amp;lt;- 」の行を書き込んでおき、NAMESPACE に export(&quot;DATA&quot;) を加えておけば、パッケージをインストールして library() でロードしたときに、パッケージの環境中に小環境として DATA が作られる。これなら .GlobalEnv を操作しないで済む。DATA の中身は ls(DATA) で閲覧できる。&lt;br /&gt;
&lt;br /&gt;
これはわかったけど、パッケージ中の至る所に get や assign があるので、これらを全部修正するのは非常に面倒。最初に知っておきたかった。</content><link rel='replies' type='application/atom+xml' href='http://bioinfomemoblog.blogspot.com/feeds/9098144085041744776/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='http://bioinfomemoblog.blogspot.com/2013/08/r-newenv.html#comment-form' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8963258932818536016/posts/default/9098144085041744776'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8963258932818536016/posts/default/9098144085041744776'/><link rel='alternate' type='text/html' href='http://bioinfomemoblog.blogspot.com/2013/08/r-newenv.html' title='R: new.env() で環境をつくる'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8963258932818536016.post-5091359462314048769</id><published>2013-08-26T00:00:00.000+09:00</published><updated>2016-07-30T12:18:01.108+09:00</updated><title type='text'>メモ：CRAN にパッケージを投稿する際の問題</title><content type='html'>メモです。&lt;br /&gt;
&lt;br /&gt;
パッケージのチェックには「--as-cran」を使う。&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;R CMD check --as-cran test.package&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Mac の Finder が自動生成する隠しファイル（.DS_Store）の存在が邪魔。これは rm で取り除くことができるから OK。&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;* checking for hidden files and directories ... NOTE&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;Found the following hidden files and directories:&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;nbsp; .DS_Store&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;These were most likely included in error. See section ‘Package&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;structure’ in the ‘Writing R Extensions’ manual.&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
assign で .GlobalEnv にオブジェクトを作ったらダメ。この解決法を知りたい。別の環境をつくってそこに放り込む？&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;* checking R code for possible problems ... NOTE&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;Found the following assignments to the global environment:&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;File ‘test.package/R/assign.obj.R’:&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;nbsp; assign(name, value, pos = .GlobalEnv)&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div id=&quot;UMS_TOOLTIP&quot; style=&quot;background-color: transparent; background-position: initial initial; background-repeat: initial initial; cursor: pointer; left: -100000px; position: absolute; top: -100000px; z-index: 2147483647;&quot;&gt;
&lt;img class=&quot;UMSRatingIcon&quot; id=&quot;ums_img_tooltip&quot; /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://bioinfomemoblog.blogspot.com/feeds/5091359462314048769/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='http://bioinfomemoblog.blogspot.com/2013/08/cran.html#comment-form' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8963258932818536016/posts/default/5091359462314048769'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8963258932818536016/posts/default/5091359462314048769'/><link rel='alternate' type='text/html' href='http://bioinfomemoblog.blogspot.com/2013/08/cran.html' title='メモ：CRAN にパッケージを投稿する際の問題'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8963258932818536016.post-2196538803277628077</id><published>2012-12-23T01:49:00.000+09:00</published><updated>2012-12-23T01:49:03.778+09:00</updated><title type='text'>R: やっぱりapply系を使い慣れておかないと</title><content type='html'>&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;Rはベクトル計算が強い。ていうかforループの多用は格好悪い。&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;いっぱい関数つくったりする前に、やっぱりapply系を使いこなしておきたい。&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;ということで、apply()の練習。&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;apply()は行列（matrix）の行（1）あるいは列（2）を対象として関数を適用する。&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;apply(X,MARGIN,FUN,OA)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;　　X: 対象とする行列&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;　　MARGIN: 1 あるいは 2&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;　　FUN: 関数&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;　　OA: FUNに与える X 以外の引数（必要時のみ）&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;まず、適当な行列をつくる&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;set.seed(0) &amp;nbsp;# 乱数のseedを規定&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;numbers &amp;lt;- rnorm(12,0,1)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;matrix1 &amp;lt;- matrix(numbers,nrow=4)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;gt; matrix1&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;[,1] &amp;nbsp; &amp;nbsp; &amp;nbsp; [,2] &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; [,3]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[1,] &amp;nbsp;1.2629543 &amp;nbsp;0.4146414 -0.005767173&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[2,] -0.3262334 -1.5399500 &amp;nbsp;2.404653389&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[3,] &amp;nbsp;1.3297993 -0.9285670 &amp;nbsp;0.763593461&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[4,] &amp;nbsp;1.2724293 -0.2947204 -0.799009249&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;行単位でmax()。&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;gt; apply(matrix1,1,max)&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[1] 1.262954 2.404653 1.329799 1.272429&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;列単位でmax()。&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;gt; apply(matrix1,2,max)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[1] 1.3297993 0.4146414 2.4046534&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;自作関数をつくってみる。関数名はf1220.1()。&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;max()で求めたxの最大値にyを足す。&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;f1220.1 &amp;lt;- function(x,y){&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;z &amp;lt;- max(x) + y&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;return(z)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;関数の動作確認。1, 2, 3の最大値に1を足すと4。&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;num123 &amp;lt;- c(1,2,3)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;gt; f1220.1(num123,1)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[1] 4&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;apply()にはFUNのoptional argumentsを与えることができる。&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;行あるいは列単位でf1220.1()を実行。引数は1。&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;gt; apply(matrix1,1,f1220.1,1)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[1] 2.262954 3.404653 2.329799 2.272429&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;gt; apply(matrix1,2,f1220.1,1)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[1] 2.329799 1.414641 3.404653&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;引数は複数でもOK。&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;f1220.2 &amp;lt;- function(x,y,a,b){&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;z &amp;lt;- max(x) + y + a + b&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;return(z)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;gt; apply(matrix1,1,f1220.2,1,1,1)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[1] 4.262954 5.404653 4.329799 4.272429&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;gt; apply(matrix1,2,f1220.2,1,1,1)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[1] 4.329799 3.414641 5.404653&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;apply()の対象となる行列に、行と列の名前がある場合。&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;colnames(matrix1) &amp;lt;- c(&quot;A&quot;,&quot;B&quot;,&quot;C&quot;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;rownames(matrix1) &amp;lt;- c(&quot;first.row&quot;,&quot;second.row&quot;,&quot;third.row&quot;,&quot;fourth.row&quot;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;gt; matrix1&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; A &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;B &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;C&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;first.row &amp;nbsp; 1.2629543 &amp;nbsp;0.4146414 -0.005767173&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;second.row -0.3262334 -1.5399500 &amp;nbsp;2.404653389&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;third.row &amp;nbsp; 1.3297993 -0.9285670 &amp;nbsp;0.763593461&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;fourth.row &amp;nbsp;1.2724293 -0.2947204 -0.799009249&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;結果はこんな風になる。&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;gt; apply(matrix1,1,max)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;first.row second.row &amp;nbsp;third.row fourth.row&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; 1.262954 &amp;nbsp; 2.404653 &amp;nbsp; 1.329799 &amp;nbsp; 1.272429&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;gt; apply(matrix1,2,max)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; A &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; B &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; C&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;1.3297993 0.4146414 2.4046534&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;次に、lapplyとsapplyの練習。&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;まず、適当なリストをつくる。&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;set.seed(0)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;a &amp;lt;- rnorm(10,0,1)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;set.seed(1)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;b &amp;lt;- rnorm(10,0,1)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;list1 &amp;lt;- list(a,b)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;gt; list1&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[[1]]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[1] &amp;nbsp;1.262954285 -0.326233361 &amp;nbsp;1.329799263 &amp;nbsp;1.272429321&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[5] &amp;nbsp;0.414641434 -1.539950042 -0.928567035 -0.294720447&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[9] -0.005767173 &amp;nbsp;2.404653389&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[[2]]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[1] -0.6264538 &amp;nbsp;0.1836433 -0.8356286 &amp;nbsp;1.5952808 &amp;nbsp;0.3295078&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[6] -0.8204684 &amp;nbsp;0.4874291 &amp;nbsp;0.7383247 &amp;nbsp;0.5757814 -0.3053884&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;lapplyはリストを対象とする。リストの各要素に対して関数を適用する。&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;gt; lapply(list1,mean)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[[1]]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[1] 0.358924&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[[2]]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[1] 0.1322028&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;sapplyはlapplyの結果をsimplifyして返す。&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;gt; sapply(list1,mean)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[1] 0.3589240 0.1322028&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;自作関数も動く。&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;f1220.3 &amp;lt;- function(x){&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;y &amp;lt;- x + 1&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;return(y)&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;gt; lapply(list1,f1220.3)&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[[1]]&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[1] &amp;nbsp;2.26295428 &amp;nbsp;0.67376664 &amp;nbsp;2.32979926 &amp;nbsp;2.27242932 &amp;nbsp;1.41464143&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[6] -0.53995004 &amp;nbsp;0.07143297 &amp;nbsp;0.70527955 &amp;nbsp;0.99423283 &amp;nbsp;3.40465339&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[[2]]&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[1] 0.3735462 1.1836433 0.1643714 2.5952808 1.3295078 0.1795316&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[7] 1.4874291 1.7383247 1.5757814 0.6946116&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;gt; sapply(list1,f1220.3)&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;[,1] &amp;nbsp; &amp;nbsp; &amp;nbsp;[,2]&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[1,] &amp;nbsp;2.26295428 0.3735462&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[2,] &amp;nbsp;0.67376664 1.1836433&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[3,] &amp;nbsp;2.32979926 0.1643714&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[4,] &amp;nbsp;2.27242932 2.5952808&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[5,] &amp;nbsp;1.41464143 1.3295078&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[6,] -0.53995004 0.1795316&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[7,] &amp;nbsp;0.07143297 1.4874291&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[8,] &amp;nbsp;0.70527955 1.7383247&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[9,] &amp;nbsp;0.99423283 1.5757814&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[10,] &amp;nbsp;3.40465339 0.6946116&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;引数を必要とする関数も動かせる。&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;f1220.4 &amp;lt;- function(x,b){&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;y &amp;lt;- x + b&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;return(y)&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;gt; lapply(list1,f1220.4,2)&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[[1]]&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[1] 3.262954 1.673767 3.329799 3.272429 2.414641 0.460050 1.071433&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[8] 1.705280 1.994233 4.404653&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[[2]]&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[1] 1.373546 2.183643 1.164371 3.595281 2.329508 1.179532 2.487429&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[8] 2.738325 2.575781 1.694612&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;gt; sapply(list1,f1220.4,2)&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; [,1] &amp;nbsp; &amp;nbsp; [,2]&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[1,] 3.262954 1.373546&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[2,] 1.673767 2.183643&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[3,] 3.329799 1.164371&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[4,] 3.272429 3.595281&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[5,] 2.414641 2.329508&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[6,] 0.460050 1.179532&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[7,] 1.071433 2.487429&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[8,] 1.705280 2.738325&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[9,] 1.994233 2.575781&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[10,] 4.404653 1.694612&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;リストの中のリストも対象にできる。&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;まず、入れ子状のリストをつくる。&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;names &amp;lt;- c(&quot;a&quot;,&quot;b&quot;,&quot;c&quot;,&quot;d&quot;,&quot;e&quot;)&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;set.seed(0)&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;value.a &amp;lt;- rnorm(10,0,1)&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;set.seed(1)&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;value.b &amp;lt;- rnorm(10,0,1)&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;set.seed(2)&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;value.c &amp;lt;- rnorm(10,0,1)&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;set.seed(3)&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;value.d &amp;lt;- rnorm(10,0,1)&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;set.seed(4)&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;value.e &amp;lt;- rnorm(10,0,1)&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;list2 &amp;lt;- list()&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;list2$names &amp;lt;- names&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;values &amp;lt;- list(a=value.a, b=value.b, c=value.c, d=value.d, e=value.e)&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;list2$values &amp;lt;- values&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;gt; list2&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;$names&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[1] &quot;a&quot; &quot;b&quot; &quot;c&quot; &quot;d&quot; &quot;e&quot;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;$values&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;$values$a&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[1] &amp;nbsp;1.262954285 -0.326233361 &amp;nbsp;1.329799263 &amp;nbsp;1.272429321&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[5] &amp;nbsp;0.414641434 -1.539950042 -0.928567035 -0.294720447&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[9] -0.005767173 &amp;nbsp;2.404653389&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;$values$b&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[1] -0.6264538 &amp;nbsp;0.1836433 -0.8356286 &amp;nbsp;1.5952808 &amp;nbsp;0.3295078&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[6] -0.8204684 &amp;nbsp;0.4874291 &amp;nbsp;0.7383247 &amp;nbsp;0.5757814 -0.3053884&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;$values$c&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[1] -0.89691455 &amp;nbsp;0.18484918 &amp;nbsp;1.58784533 -1.13037567 -0.08025176&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[6] &amp;nbsp;0.13242028 &amp;nbsp;0.70795473 -0.23969802 &amp;nbsp;1.98447394 -0.13878701&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;$values$d&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[1] -0.96193342 -0.29252572 &amp;nbsp;0.25878822 -1.15213189 &amp;nbsp;0.19578283&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[6] &amp;nbsp;0.03012394 &amp;nbsp;0.08541773 &amp;nbsp;1.11661021 -1.21885742 &amp;nbsp;1.26736872&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;$values$e&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[1] &amp;nbsp;0.2167549 -0.5424926 &amp;nbsp;0.8911446 &amp;nbsp;0.5959806 &amp;nbsp;1.6356180&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[6] &amp;nbsp;0.6892754 -1.2812466 -0.2131445 &amp;nbsp;1.8965399 &amp;nbsp;1.7768632&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;クラスを確認。&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;







&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&amp;gt; &lt;/span&gt;class(list2)&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
[1] &quot;list&quot;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&amp;gt; &lt;/span&gt;class(list2$values)&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
[1] &quot;list&quot;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;入れ子のリストにlapply()を適用。&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;gt; lapply(list2$values,mean)&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;$a&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[1] 0.358924&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;$b&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[1] 0.1322028&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;$c&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[1] 0.2111516&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;$d&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[1] -0.06713568&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;$e&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[1] 0.5665293&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;sapply()も動く。&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;gt; sapply(list2$values,mean)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; a &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; b &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; c &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; d &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; e&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;0.35892396 &amp;nbsp;0.13220278 &amp;nbsp;0.21115165 -0.06713568 &amp;nbsp;0.56652929&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;リストの中の行列にはapply()が使える。&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;まず、行列を含むリストをつくる。&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;list3 &amp;lt;- list()&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;list3$names &amp;lt;- names&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;values &amp;lt;- cbind(a=value.a, b=value.b, c=value.c, d=value.d, e=value.e)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;rownames(values) &amp;lt;- seq(1,10,1)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;list3$values &amp;lt;- values&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;gt; list3&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;$names&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[1] &quot;a&quot; &quot;b&quot; &quot;c&quot; &quot;d&quot; &quot;e&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;$values&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; a &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;b &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; c &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; d &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;e&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;1 &amp;nbsp; 1.262954285 -0.6264538 -0.89691455 -0.96193342 &amp;nbsp;0.2167549&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;2 &amp;nbsp;-0.326233361 &amp;nbsp;0.1836433 &amp;nbsp;0.18484918 -0.29252572 -0.5424926&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;3 &amp;nbsp; 1.329799263 -0.8356286 &amp;nbsp;1.58784533 &amp;nbsp;0.25878822 &amp;nbsp;0.8911446&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;4 &amp;nbsp; 1.272429321 &amp;nbsp;1.5952808 -1.13037567 -1.15213189 &amp;nbsp;0.5959806&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;5 &amp;nbsp; 0.414641434 &amp;nbsp;0.3295078 -0.08025176 &amp;nbsp;0.19578283 &amp;nbsp;1.6356180&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;6 &amp;nbsp;-1.539950042 -0.8204684 &amp;nbsp;0.13242028 &amp;nbsp;0.03012394 &amp;nbsp;0.6892754&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;7 &amp;nbsp;-0.928567035 &amp;nbsp;0.4874291 &amp;nbsp;0.70795473 &amp;nbsp;0.08541773 -1.2812466&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;8 &amp;nbsp;-0.294720447 &amp;nbsp;0.7383247 -0.23969802 &amp;nbsp;1.11661021 -0.2131445&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;9 &amp;nbsp;-0.005767173 &amp;nbsp;0.5757814 &amp;nbsp;1.98447394 -1.21885742 &amp;nbsp;1.8965399&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;10 &amp;nbsp;2.404653389 -0.3053884 -0.13878701 &amp;nbsp;1.26736872 &amp;nbsp;1.7768632&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;クラスを確認。&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;gt; class(list3)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[1] &quot;list&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;gt; class(list3$values)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[1] &quot;matrix&quot;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;apply()を動かす。&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;gt; apply(list3$values,1,max)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 4 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 5 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 6&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;1.2629543 0.1848492 1.5878453 1.5952808 1.6356180 0.6892754&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 7 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 8 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 9 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;10&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;0.7079547 1.1166102 1.9844739 2.4046534&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;gt; apply(list3$values,2,max)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;a &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;b &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;c &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;d &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;e&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;2.404653 1.595281 1.984474 1.267369 1.896540&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;こういうのをちゃんと理解してから複雑な仕事をした方が良い。&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
</content><link rel='replies' type='application/atom+xml' href='http://bioinfomemoblog.blogspot.com/feeds/2196538803277628077/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='http://bioinfomemoblog.blogspot.com/2012/12/r-apply.html#comment-form' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8963258932818536016/posts/default/2196538803277628077'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8963258932818536016/posts/default/2196538803277628077'/><link rel='alternate' type='text/html' href='http://bioinfomemoblog.blogspot.com/2012/12/r-apply.html' title='R: やっぱりapply系を使い慣れておかないと'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8963258932818536016.post-7763852186993697351</id><published>2012-10-14T22:50:00.001+09:00</published><updated>2012-10-14T23:19:32.811+09:00</updated><title type='text'>R: グラフの誤差範囲（標準偏差）をグレー表示</title><content type='html'>Rでグラフを作る際、エラーバーの代わりにグレーで視覚化する。&lt;br /&gt;
例えば、５サンプルのグラフ。&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgRgN9vzXOgEnu71z0HUiMT77ezkSStAqUp-C9UY0NOyYfV_AryoefxvidwAHeraWmUHH6hVSnNtnoZY3iUbAAIJ_ZYvIjnIPX8y6W0BJcvrqTTEnYjsYMT32Ugdof02QG4phK2VDC0wJdV/s1600/graph_error.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgRgN9vzXOgEnu71z0HUiMT77ezkSStAqUp-C9UY0NOyYfV_AryoefxvidwAHeraWmUHH6hVSnNtnoZY3iUbAAIJ_ZYvIjnIPX8y6W0BJcvrqTTEnYjsYMT32Ugdof02QG4phK2VDC0wJdV/s320/graph_error.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;標準偏差をグレー表示&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;#&amp;nbsp;インデックスは10。&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;len &amp;lt;- 10&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;# 5サンプルのデータを適当につくる。平均値は10。&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;a &amp;lt;- rnorm(len,10,1)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;b &amp;lt;- rnorm(len,10,1)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;c &amp;lt;- rnorm(len,10,1)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;d &amp;lt;- rnorm(len,10,1)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;e &amp;lt;- rnorm(len,10,1)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;# 行列にする&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;main.table &amp;lt;- rbind(a,b,c,d,e)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;# 平均と標準偏差を計算する&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;main.mean &amp;lt;- apply(main.table,2,mean)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;main.sd &amp;lt;- apply(main.table,2,sd)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;# ポリゴンのx座標とy座標をつくる&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;x &amp;lt;- 1:len&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;poly.x &amp;lt;- c(x,rev(x))&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;/div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;poly.y &amp;lt;- c(main.mean+main.sd,rev(main.mean-main.sd))&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;# プロットする。最初はデータを入れずy軸はエラー分の余裕をつくる。&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;# ポリゴンを入れる。グレーで埋めて、輪郭線は消す。&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;# 線をプロットする。&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;plot(main.mean,type=&quot;n&quot;,ylim=c(min(main.mean)-max(main.sd),max(main.mean)+max(main.sd)),)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;polygon(poly.x,poly.y,col=&quot;gray&quot;,lty=0)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;lines(main.mean,lwd=2)&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;# 別ウィンドウで個別データをプロット&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;quartz(&quot;each&quot;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;plot(main.table[a],type=&quot;n&quot;,ylim=c(min(main.mean)-max(main.sd),max(main.mean)+max(main.sd)),)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;lines(main.table[a])&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;lines(main.table[b])&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;lines(main.table[c])&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;lines(main.table[d])&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;lines(main.table[e])&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://bioinfomemoblog.blogspot.com/feeds/7763852186993697351/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='http://bioinfomemoblog.blogspot.com/2012/10/r_14.html#comment-form' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8963258932818536016/posts/default/7763852186993697351'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8963258932818536016/posts/default/7763852186993697351'/><link rel='alternate' type='text/html' href='http://bioinfomemoblog.blogspot.com/2012/10/r_14.html' title='R: グラフの誤差範囲（標準偏差）をグレー表示'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgRgN9vzXOgEnu71z0HUiMT77ezkSStAqUp-C9UY0NOyYfV_AryoefxvidwAHeraWmUHH6hVSnNtnoZY3iUbAAIJ_ZYvIjnIPX8y6W0BJcvrqTTEnYjsYMT32Ugdof02QG4phK2VDC0wJdV/s72-c/graph_error.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8963258932818536016.post-3708474284352387092</id><published>2012-10-14T02:09:00.001+09:00</published><updated>2012-10-14T02:18:22.207+09:00</updated><title type='text'>R: wigもつくる</title><content type='html'>せっかく自動でgffをつくったので、wigもつくってみる。&lt;br /&gt;
まず、&lt;a href=&quot;http://bioinfomemoblog.blogspot.jp/2012/10/r-gff.html&quot; target=&quot;_blank&quot;&gt;前回&lt;/a&gt;の「gff.gen()」に若干の修正を加えてgffを得る。&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;gff&lt;/span&gt;をつくる関数&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;gff.gen &amp;lt;- function(n=1000,chrnum=3,type=&quot;protein_coding&quot;){&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;chrs &amp;lt;- paste(&quot;chr&quot;,1:chrnum,sep=&quot;&quot;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;source &amp;lt;- &quot;R&quot;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;type &amp;lt;- type&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;dots &amp;lt;- rep(&quot;.&quot;,n)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;chr &amp;lt;- sample(chrs,n,replace=T)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;start &amp;lt;- sample(1:9990000,n)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;end &amp;lt;- start+1500+(round(rnorm(n)/2*500))&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;strand &amp;lt;- sample(c(&quot;+&quot;,&quot;-&quot;),n,replace=T,prob=c(0.5,0.5))&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;id &amp;lt;- paste(&quot;gene&quot;,1:n,sep=&quot;&quot;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;gff &amp;lt;- data.frame(chr,source,type,start,end,dots,strand,dots,id)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;return(gff)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;gff&lt;/span&gt;をつくって&lt;a href=&quot;http://bioinfomemoblog.blogspot.jp/2012/10/r.html&quot; target=&quot;_blank&quot;&gt;ソート&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p4&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;gff &amp;lt;- gff.gen(1000,3,&quot;protein_coding&quot;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p4&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;gff &amp;lt;- sort.left(gff)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p4&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p4&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p4&quot;&gt;
このgffの中の一部の遺伝子の5&#39;末端にふくらみのあるwigをつくる。&lt;/div&gt;
&lt;div class=&quot;p4&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p4&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;span class=&quot;s1&quot;&gt;# wig&lt;/span&gt;をつくる関数（上のgffがあることが前提）&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;wig.gen &amp;lt;- function(chrnum=3){&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;span class=&quot;s1&quot;&gt;# chr&lt;/span&gt;の名前をつくる&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p4&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;chrs &amp;lt;- paste(&quot;chr&quot;,1:chrnum,sep=&quot;&quot;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;span class=&quot;s1&quot;&gt;# chr&lt;/span&gt;毎に作業する&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;for (i in 1:length(chrs)){&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;chr &amp;lt;- chrs[i]&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;# header&lt;span class=&quot;s2&quot;&gt;をつくる&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;wig.head1 &amp;lt;- paste(&quot;track type=wiggle_0 name=\&quot;&quot;,chr,&quot;\&quot; description=\&quot;generated by R\&quot;&quot;,sep=&quot;&quot;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;wig.head2 &amp;lt;- paste(&quot;variableStep chrom=&quot;,chr,&quot; span=10&quot;,sep=&quot;&quot;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;wig.head &amp;lt;- c(wig.head1,wig.head2)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;wig.head.file &amp;lt;- paste(&quot;head_&quot;,chr,&quot;.txt&quot;,sep=&quot;&quot;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;write(wig.head,file=wig.head.file)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;# body&lt;span class=&quot;s2&quot;&gt;をつくる&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;n &amp;lt;- 10000000&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;step &amp;lt;- 10&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;pos &amp;lt;- seq(1,n,step)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;depth &amp;lt;- round(rnorm(1:length(pos),100,sd=2))&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;wig.body &amp;lt;- cbind(pos,depth)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p5&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;# chr毎のgffをつくる&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;assign(paste(&quot;gff.&quot;,chr,&quot;.fw&quot;,sep=&quot;&quot;),gff[gff$chr==chr&amp;amp;gff$strand==&quot;+&quot;,])&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;assign(paste(&quot;gff.&quot;,chr,&quot;.rv&quot;,sep=&quot;&quot;),gff[gff$chr==chr&amp;amp;gff$strand==&quot;-&quot;,])&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;# bodyに変化を加える&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;y.rep &amp;lt;- nrow(get(paste(&quot;gff.&quot;,chr,&quot;.fw&quot;,sep=&quot;&quot;)))%/%5&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;for(y in 1:y.rep) {&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;tss &amp;lt;- sample(get(paste(&quot;gff.&quot;,chr,&quot;.fw&quot;,sep=&quot;&quot;))[,4],1)%/%10&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;upst &amp;lt;- tss-19&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;dnst &amp;lt;- tss+20&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;hight &amp;lt;- sample(1:2000,1)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;add.tag.upst &amp;lt;- round((cos(seq(1*pi,0,length=20))+1)*hight)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;add.tag.dnst &amp;lt;- round((cos(seq(0,1*pi,length=20))+1)*hight)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;wig.body[upst:tss,2] &amp;lt;- wig.body[upst:tss,2]+add.tag.upst&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;wig.body[(tss+1):dnst,2] &amp;lt;- wig.body[(tss+1):dnst,2]+add.tag.dnst&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;tss &amp;lt;- sample(get(paste(&quot;gff.&quot;,chr,&quot;.rv&quot;,sep=&quot;&quot;))[,5],1)%/%10&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;upst &amp;lt;- tss-19&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;dnst &amp;lt;- tss+20&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;hight &amp;lt;- sample(1:2000,1)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;add.tag.upst &amp;lt;- round((cos(seq(1*pi,0,length=20))+1)*hight)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;add.tag.dnst &amp;lt;- round((cos(seq(0,1*pi,length=20))+1)*hight)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;wig.body[upst:tss,2] &amp;lt;- wig.body[upst:tss,2]+add.tag.upst&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;wig.body[(tss+1):dnst,2] &amp;lt;- wig.body[(tss+1):dnst,2]+add.tag.dnst&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p5&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;# bodyを保存する&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;wig.body.file &amp;lt;- paste(&quot;body_&quot;,chr,&quot;.txt&quot;,sep=&quot;&quot;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;write.table(wig.body,file=wig.body.file,col.names=F,row.names=F,sep=&quot; &quot;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;# header&lt;span class=&quot;s2&quot;&gt;と&lt;/span&gt;body&lt;span class=&quot;s2&quot;&gt;をつなげる&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;wig.file &amp;lt;- paste(chr,&quot;.wig&quot;,sep=&quot;&quot;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;sys.command &amp;lt;- paste(&quot;cat&quot;,wig.head.file,wig.body.file,&quot;&amp;gt;&quot;,wig.file,sep=&quot; &quot;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;system(sys.command)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;span class=&quot;s1&quot;&gt;# &lt;/span&gt;headerとbodyを消す&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;system(paste(&quot;rm&quot;,wig.head.file,sep=&quot; &quot;))&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;system(paste(&quot;rm&quot;,wig.body.file,sep=&quot; &quot;))&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;span class=&quot;s1&quot;&gt;} # chr&lt;/span&gt;毎のループはここまで&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;span class=&quot;s1&quot;&gt;} # &lt;/span&gt;この関数はここまで&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
上の関数を使ってwigをつくる&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;wig.gen(3)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://bioinfomemoblog.blogspot.com/feeds/3708474284352387092/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='http://bioinfomemoblog.blogspot.com/2012/10/r-wig.html#comment-form' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8963258932818536016/posts/default/3708474284352387092'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8963258932818536016/posts/default/3708474284352387092'/><link rel='alternate' type='text/html' href='http://bioinfomemoblog.blogspot.com/2012/10/r-wig.html' title='R: wigもつくる'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8963258932818536016.post-2151052364730702652</id><published>2012-10-12T22:31:00.001+09:00</published><updated>2012-10-12T22:34:56.346+09:00</updated><title type='text'>R: gffをつくる</title><content type='html'>いくつかの解析系のことを考えていると、gffフォーマットのファイルが欲しくなった。Rで自動生成してみる。&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;gff&lt;/span&gt;ファイルをつくる関数&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
行数と染色体の数、それとタイプを指定してgffの中身をランダムに生成する。&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;# n: &lt;span class=&quot;s2&quot;&gt;行数&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;# chrnum: &lt;span class=&quot;s2&quot;&gt;染色体の数&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;# type: &quot;protein_coding&quot;, etc.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;gff.gen &amp;lt;- function(n,chrnum,type){&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;chrs &amp;lt;- paste(&quot;chr&quot;,1:chrnum,sep=&quot;&quot;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;source &amp;lt;- &quot;R&quot;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;type &amp;lt;- type&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;dots &amp;lt;- rep(&quot;.&quot;,n)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;chr &amp;lt;- sample(chrs,n,replace=T)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;start &amp;lt;- abs(round(rnorm(n)*1000000))&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;end &amp;lt;- start+1500+(round(rnorm(n)/2*500))&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;strand &amp;lt;- sample(c(&quot;+&quot;,&quot;-&quot;),n,replace=T,prob=c(0.5,0.5))&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;id &amp;lt;- paste(&quot;gene&quot;,1:n,sep=&quot;&quot;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;gff &amp;lt;- data.frame(chr,source,type,start,end,dots,strand,dots,id)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;return(gff)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;# usage&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;gff &amp;lt;- gff.gen(1000,3,&quot;ncRNA&quot;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;# check&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;head(gff)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;# min length&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;min(gff[,5]-gff[,4])&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;# distribution&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;hist(gff[,5]-gff[,4],main=&quot;gene length&quot;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;# sort.left&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;gff.s &amp;lt;- sort.left(gff)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;# check&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;head(gff.s)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;# number of each strand&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;nrow(gff.s[gff.s$strand==&quot;+&quot;,])&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;nrow(gff.s[gff.s$strand==&quot;-&quot;,])&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
関数「sort.left()」は&lt;a href=&quot;http://bioinfomemoblog.blogspot.jp/2012/10/r.html&quot; target=&quot;_blank&quot;&gt;こちら&lt;/a&gt;を参照。&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
上の「# usage」以下の実行結果。&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;gt; # usage&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;gt; gff &amp;lt;- gff.gen(1000,3,&quot;ncRNA&quot;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;gt; # check&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;gt; head(gff)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp;chr source &amp;nbsp;type &amp;nbsp; start &amp;nbsp; &amp;nbsp; end dots strand dots.1 &amp;nbsp; &amp;nbsp;id&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;1 chr2 &amp;nbsp; &amp;nbsp; &amp;nbsp;R ncRNA &amp;nbsp;272400 &amp;nbsp;273456 &amp;nbsp; &amp;nbsp;. &amp;nbsp; &amp;nbsp; &amp;nbsp;- &amp;nbsp; &amp;nbsp; &amp;nbsp;. gene1&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;2 chr1 &amp;nbsp; &amp;nbsp; &amp;nbsp;R ncRNA 1173705 1175235 &amp;nbsp; &amp;nbsp;. &amp;nbsp; &amp;nbsp; &amp;nbsp;+ &amp;nbsp; &amp;nbsp; &amp;nbsp;. gene2&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;3 chr1 &amp;nbsp; &amp;nbsp; &amp;nbsp;R ncRNA &amp;nbsp;726009 &amp;nbsp;727790 &amp;nbsp; &amp;nbsp;. &amp;nbsp; &amp;nbsp; &amp;nbsp;+ &amp;nbsp; &amp;nbsp; &amp;nbsp;. gene3&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;4 chr3 &amp;nbsp; &amp;nbsp; &amp;nbsp;R ncRNA 2041368 2042869 &amp;nbsp; &amp;nbsp;. &amp;nbsp; &amp;nbsp; &amp;nbsp;- &amp;nbsp; &amp;nbsp; &amp;nbsp;. gene4&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;5 chr3 &amp;nbsp; &amp;nbsp; &amp;nbsp;R ncRNA &amp;nbsp;607172 &amp;nbsp;608515 &amp;nbsp; &amp;nbsp;. &amp;nbsp; &amp;nbsp; &amp;nbsp;+ &amp;nbsp; &amp;nbsp; &amp;nbsp;. gene5&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;6 chr3 &amp;nbsp; &amp;nbsp; &amp;nbsp;R ncRNA &amp;nbsp;556786 &amp;nbsp;558183 &amp;nbsp; &amp;nbsp;. &amp;nbsp; &amp;nbsp; &amp;nbsp;+ &amp;nbsp; &amp;nbsp; &amp;nbsp;. gene6&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;gt; # min length&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;gt; min(gff[,5]-gff[,4])&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[1] 767&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;gt; # distribution&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;gt; hist(gff[,5]-gff[,4],main=&quot;gene length&quot;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjcWGPqoyrbZrLuvIe63Tk6tSj7JQ_qKwXod2jV4gZJRuLwkWTYoHnAqsmG9xC8aTcA3kgkC2vRhjyAAIJPd4Bpk-pV_Zx4PCVRspzHfqwW0NFQ7JDLoeMx76d7iAykKpwU6w7JDYl5ufQe/s1600/Rplot.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; margin-bottom: 1em; margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjcWGPqoyrbZrLuvIe63Tk6tSj7JQ_qKwXod2jV4gZJRuLwkWTYoHnAqsmG9xC8aTcA3kgkC2vRhjyAAIJPd4Bpk-pV_Zx4PCVRspzHfqwW0NFQ7JDLoeMx76d7iAykKpwU6w7JDYl5ufQe/s320/Rplot.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;histの結果&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;gt; # sort.left&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;gt; gff.s &amp;lt;- sort.left(gff)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;gt; # check&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;gt; head(gff.s)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;chr source &amp;nbsp;type start &amp;nbsp; end dots strand dots.1 &amp;nbsp; &amp;nbsp; &amp;nbsp;id&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;150 chr1 &amp;nbsp; &amp;nbsp; &amp;nbsp;R ncRNA &amp;nbsp;1017 &amp;nbsp;2463 &amp;nbsp; &amp;nbsp;. &amp;nbsp; &amp;nbsp; &amp;nbsp;- &amp;nbsp; &amp;nbsp; &amp;nbsp;. gene150&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;378 chr1 &amp;nbsp; &amp;nbsp; &amp;nbsp;R ncRNA &amp;nbsp;9260 11146 &amp;nbsp; &amp;nbsp;. &amp;nbsp; &amp;nbsp; &amp;nbsp;- &amp;nbsp; &amp;nbsp; &amp;nbsp;. gene378&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;164 chr1 &amp;nbsp; &amp;nbsp; &amp;nbsp;R ncRNA &amp;nbsp;9922 10844 &amp;nbsp; &amp;nbsp;. &amp;nbsp; &amp;nbsp; &amp;nbsp;+ &amp;nbsp; &amp;nbsp; &amp;nbsp;. gene164&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;93 &amp;nbsp;chr1 &amp;nbsp; &amp;nbsp; &amp;nbsp;R ncRNA 14776 15981 &amp;nbsp; &amp;nbsp;. &amp;nbsp; &amp;nbsp; &amp;nbsp;+ &amp;nbsp; &amp;nbsp; &amp;nbsp;. &amp;nbsp;gene93&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;557 chr1 &amp;nbsp; &amp;nbsp; &amp;nbsp;R ncRNA 17269 18323 &amp;nbsp; &amp;nbsp;. &amp;nbsp; &amp;nbsp; &amp;nbsp;+ &amp;nbsp; &amp;nbsp; &amp;nbsp;. gene557&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;863 chr1 &amp;nbsp; &amp;nbsp; &amp;nbsp;R ncRNA 21640 22834 &amp;nbsp; &amp;nbsp;. &amp;nbsp; &amp;nbsp; &amp;nbsp;- &amp;nbsp; &amp;nbsp; &amp;nbsp;. gene863&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;gt; # number of each strand&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;gt; nrow(gff.s[gff.s$strand==&quot;+&quot;,])&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[1] 495&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;gt; nrow(gff.s[gff.s$strand==&quot;-&quot;,])&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[1] 505&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://bioinfomemoblog.blogspot.com/feeds/2151052364730702652/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='http://bioinfomemoblog.blogspot.com/2012/10/r-gff.html#comment-form' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8963258932818536016/posts/default/2151052364730702652'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8963258932818536016/posts/default/2151052364730702652'/><link rel='alternate' type='text/html' href='http://bioinfomemoblog.blogspot.com/2012/10/r-gff.html' title='R: gffをつくる'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjcWGPqoyrbZrLuvIe63Tk6tSj7JQ_qKwXod2jV4gZJRuLwkWTYoHnAqsmG9xC8aTcA3kgkC2vRhjyAAIJPd4Bpk-pV_Zx4PCVRspzHfqwW0NFQ7JDLoeMx76d7iAykKpwU6w7JDYl5ufQe/s72-c/Rplot.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8963258932818536016.post-6540093443235733209</id><published>2012-10-12T12:22:00.003+09:00</published><updated>2012-10-12T12:32:28.874+09:00</updated><title type='text'>R: 左側のカラムを優先して全カラムをソートする</title><content type='html'>&lt;span style=&quot;font-family: inherit;&quot;&gt;PeakAnnotatorを使ってみたら、順番に並んでないから無理と言われた。&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;こんな結果。&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;$ PeakAnnotator TSS peaks.bed genes.bed out/tss.txt&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;Starting...&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;Reading BED File&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;Files must be sorted by chromosomes,start position, end position&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;ということで、左のカラムを優先して全カラムをソートする関数を作った。&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;行列xに適用すれば並べ替えてくれる。普遍的に使える。列数の限界なし。&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;








&lt;br /&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;b&gt;sort.left &amp;lt;- function(x,decreasing=FALSE){&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;b&gt;n &amp;lt;- ncol(x)&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;b&gt;colnum &amp;lt;- n&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;b&gt;for (i in 1:n){&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;b&gt;x &amp;lt;- x[order(x[,colnum],decreasing=decreasing),]&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;b&gt;colnum &amp;lt;- colnum-1&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;b&gt;}&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;b&gt;return(x)&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;b&gt;}&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
以下、挙動の確認&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
４列のマトリックスに１から８をランダムに入れた。&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;span class=&quot;s1&quot;&gt;&amp;gt; &lt;/span&gt;x &amp;lt;- matrix(sample(1:8,4*16,replace=T),ncol=4)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
xの中身を確認。&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;gt; &lt;span class=&quot;s2&quot;&gt;x&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; [,1] [,2] [,3] [,4]&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[1,]&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; 2&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[2,]&amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; 8&amp;nbsp; &amp;nbsp; 2&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[3,]&amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; 6&amp;nbsp; &amp;nbsp; 8&amp;nbsp; &amp;nbsp; 1&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[4,]&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; 6&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; 4&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[5,]&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; 4&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[6,]&amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; 6&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; 7&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[7,]&amp;nbsp; &amp;nbsp; 7&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; 6&amp;nbsp; &amp;nbsp; 1&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[8,]&amp;nbsp; &amp;nbsp; 7&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; 8&amp;nbsp; &amp;nbsp; 7&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[9,]&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; 8&amp;nbsp; &amp;nbsp; 8&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[10,]&amp;nbsp; &amp;nbsp; 8&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; 6&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[11,]&amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; 4&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[12,]&amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; 5&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[13,]&amp;nbsp; &amp;nbsp; 8&amp;nbsp; &amp;nbsp; 7&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; 7&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[14,]&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; 7&amp;nbsp; &amp;nbsp; 5&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[15,]&amp;nbsp; &amp;nbsp; 6&amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; 7&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[16,]&amp;nbsp; &amp;nbsp; 6&amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; 6&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
関数「sort.left()」を適用。&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
１列目が同じ場合には２列目（１行目と２行目を参照）が、２列目まで同じ場合には３列目（９行目から１４行目参照）が、ちゃんと昇順になっているのがわかる。&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;span class=&quot;s1&quot;&gt;&amp;gt; &lt;/span&gt;sort.left(x)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; [,1] [,2] [,3] [,4]&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[1,]&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; 4&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[2,]&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; 2&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[3,]&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; 6&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; 4&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[4,]&amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; 8&amp;nbsp; &amp;nbsp; 2&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[5,]&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; 8&amp;nbsp; &amp;nbsp; 8&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[6,]&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; 7&amp;nbsp; &amp;nbsp; 5&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[7,]&amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; 5&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[8,]&amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; 4&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[9,]&amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; 6&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; 7&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[10,]&amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; 6&amp;nbsp; &amp;nbsp; 8&amp;nbsp; &amp;nbsp; 1&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[11,]&amp;nbsp; &amp;nbsp; 6&amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; 7&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[12,]&amp;nbsp; &amp;nbsp; 6&amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; 6&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[13,]&amp;nbsp; &amp;nbsp; 7&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; 6&amp;nbsp; &amp;nbsp; 1&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[14,]&amp;nbsp; &amp;nbsp; 7&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; 8&amp;nbsp; &amp;nbsp; 7&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[15,]&amp;nbsp; &amp;nbsp; 8&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; 6&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[16,]&amp;nbsp; &amp;nbsp; 8&amp;nbsp; &amp;nbsp; 7&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; 7&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;引数の「decreasing」はデフォルトでFALSEだが、&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;TRUEを与えると降順になる。&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;span class=&quot;s1&quot;&gt;&amp;gt; &lt;/span&gt;sort.left(x,T)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; [,1] [,2] [,3] [,4]&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[1,]&amp;nbsp; &amp;nbsp; 8&amp;nbsp; &amp;nbsp; 7&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; 7&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[2,]&amp;nbsp; &amp;nbsp; 8&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; 6&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[3,]&amp;nbsp; &amp;nbsp; 7&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; 8&amp;nbsp; &amp;nbsp; 7&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[4,]&amp;nbsp; &amp;nbsp; 7&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; 6&amp;nbsp; &amp;nbsp; 1&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[5,]&amp;nbsp; &amp;nbsp; 6&amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; 6&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[6,]&amp;nbsp; &amp;nbsp; 6&amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; 7&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[7,]&amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; 6&amp;nbsp; &amp;nbsp; 8&amp;nbsp; &amp;nbsp; 1&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[8,]&amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; 6&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; 7&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[9,]&amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; 4&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[10,]&amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; 5&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[11,]&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; 7&amp;nbsp; &amp;nbsp; 5&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[12,]&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; 8&amp;nbsp; &amp;nbsp; 8&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[13,]&amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; 8&amp;nbsp; &amp;nbsp; 2&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[14,]&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; 6&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; 4&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[15,]&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; 2&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[16,]&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; 4&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;せっかくなので、右側優先の関数もつくった。&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;b&gt;sort.right &amp;lt;- function(x,decreasing=FALSE){&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;b&gt;n &amp;lt;- ncol(x)&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;b&gt;colnum &amp;lt;- n&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;b style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;for (i in 1:n){&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;b&gt;x &amp;lt;- x[order(x[,n-colnum+1],decreasing=decreasing),]&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;b&gt;colnum &amp;lt;- colnum-1&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;b&gt;}&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;b&gt;return(x)&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;b&gt;}&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;xに関数「sort.right()」を適用。&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
最右列から優先的にソートされる。&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;span class=&quot;s1&quot;&gt;&amp;gt; &lt;/span&gt;sort.right(x)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; [,1] [,2] [,3] [,4]&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[1,]&amp;nbsp; &amp;nbsp; 7&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; 6&amp;nbsp; &amp;nbsp; 1&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[2,]&amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; 6&amp;nbsp; &amp;nbsp; 8&amp;nbsp; &amp;nbsp; 1&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[3,]&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; 2&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[4,]&amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; 8&amp;nbsp; &amp;nbsp; 2&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[5,]&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; 4&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[6,]&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; 6&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; 4&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[7,]&amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; 4&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[8,]&amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; 5&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[9,]&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; 7&amp;nbsp; &amp;nbsp; 5&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[10,]&amp;nbsp; &amp;nbsp; 8&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; 6&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[11,]&amp;nbsp; &amp;nbsp; 6&amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; 6&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[12,]&amp;nbsp; &amp;nbsp; 6&amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; 7&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[13,]&amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; 6&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; 7&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[14,]&amp;nbsp; &amp;nbsp; 8&amp;nbsp; &amp;nbsp; 7&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; 7&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[15,]&amp;nbsp; &amp;nbsp; 7&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; 8&amp;nbsp; &amp;nbsp; 7&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[16,]&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; 8&amp;nbsp; &amp;nbsp; 8&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;もちろん降順もできる。&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;span class=&quot;s1&quot;&gt;&amp;gt; &lt;/span&gt;sort.right(x,T)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; [,1] [,2] [,3] [,4]&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[1,]&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; 8&amp;nbsp; &amp;nbsp; 8&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[2,]&amp;nbsp; &amp;nbsp; 7&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; 8&amp;nbsp; &amp;nbsp; 7&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[3,]&amp;nbsp; &amp;nbsp; 8&amp;nbsp; &amp;nbsp; 7&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; 7&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[4,]&amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; 6&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; 7&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[5,]&amp;nbsp; &amp;nbsp; 6&amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; 7&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[6,]&amp;nbsp; &amp;nbsp; 6&amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; 6&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[7,]&amp;nbsp; &amp;nbsp; 8&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; 6&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[8,]&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; 7&amp;nbsp; &amp;nbsp; 5&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[9,]&amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; 5&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[10,]&amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; 4&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[11,]&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; 6&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; 4&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[12,]&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; 4&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[13,]&amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; 8&amp;nbsp; &amp;nbsp; 2&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[14,]&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; 2&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[15,]&amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; 6&amp;nbsp; &amp;nbsp; 8&amp;nbsp; &amp;nbsp; 1&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[16,]&amp;nbsp; &amp;nbsp; 7&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; 6&amp;nbsp; &amp;nbsp; 1&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;列が増えても大丈夫。&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;span class=&quot;s1&quot;&gt;&amp;gt; &lt;/span&gt;y &amp;lt;- matrix(sample(1:4,6*16,replace=T),ncol=6)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;span class=&quot;s1&quot;&gt;&amp;gt; &lt;/span&gt;sort.left(y)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; [,1] [,2] [,3] [,4] [,5] [,6]&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[1,]&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; 3&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[2,]&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; 4&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[3,]&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; 2&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[4,]&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; 3&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[5,]&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; 1&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[6,]&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; 3&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[7,]&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; 3&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[8,]&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; 4&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[9,]&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; 4&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[10,]&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; 4&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[11,]&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; 3&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[12,]&amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; 1&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[13,]&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; 3&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[14,]&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; 2&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[15,]&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; 3&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[16,]&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; 1&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;span class=&quot;s1&quot;&gt;&amp;gt; &lt;/span&gt;sort.right(y,T)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; [,1] [,2] [,3] [,4] [,5] [,6]&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[1,]&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; 4&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[2,]&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; 4&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[3,]&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; 4&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[4,]&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; 4&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[5,]&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; 3&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[6,]&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; 3&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[7,]&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; 3&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[8,]&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; 3&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;[9,]&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; 3&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[10,]&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; 3&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[11,]&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; 3&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[12,]&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; 2&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[13,]&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; 2&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[14,]&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; 1&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[15,]&amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; 1&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[16,]&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; 1&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://bioinfomemoblog.blogspot.com/feeds/6540093443235733209/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='http://bioinfomemoblog.blogspot.com/2012/10/r.html#comment-form' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8963258932818536016/posts/default/6540093443235733209'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8963258932818536016/posts/default/6540093443235733209'/><link rel='alternate' type='text/html' href='http://bioinfomemoblog.blogspot.com/2012/10/r.html' title='R: 左側のカラムを優先して全カラムをソートする'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8963258932818536016.post-1607588584815826820</id><published>2012-06-19T14:00:00.000+09:00</published><updated>2012-06-19T14:00:49.641+09:00</updated><title type='text'>MEMEが見つけるモチーフの中身</title><content type='html'>たとえ&lt;a href=&quot;http://bioinfomemoblog.blogspot.jp/2012/06/meme_11.html&quot; target=&quot;_blank&quot;&gt;リピートをマスキングしてから実行&lt;/a&gt;したとしても、MEMEは沢山のモチーフを提示してくれる。&lt;br /&gt;
&lt;br /&gt;
ランダムにサンプリングしたプロモーター配列をMEMEに渡すと、MEMEが発見するモチーフの傾向がつかめる。&lt;br /&gt;
&lt;br /&gt;
転写開始点付近のGCに富む領域、Alu配列の下流にあるA-richな領域などが目立つ。A-richな領域はリピートマスキングでもマスクされないのでどうしてもMEMEが拾ってしまう。&lt;br /&gt;
&lt;br /&gt;
ハズレらしきモチーフは極端に長い傾向にある。特にGCに富む領域の場合、ひとつの配列に類似のモチーフが複数見つかる。もちろん、ハズレと断定できるわけではないのだが、このような傾向があることを知っておくのは重要だと思う。</content><link rel='replies' type='application/atom+xml' href='http://bioinfomemoblog.blogspot.com/feeds/1607588584815826820/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='http://bioinfomemoblog.blogspot.com/2012/06/meme_19.html#comment-form' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8963258932818536016/posts/default/1607588584815826820'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8963258932818536016/posts/default/1607588584815826820'/><link rel='alternate' type='text/html' href='http://bioinfomemoblog.blogspot.com/2012/06/meme_19.html' title='MEMEが見つけるモチーフの中身'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8963258932818536016.post-3556349531052364239</id><published>2012-06-19T13:53:00.002+09:00</published><updated>2012-06-19T13:53:53.847+09:00</updated><title type='text'>PowerPointの低い解像度について</title><content type='html'>&lt;span style=&quot;font-family: inherit;&quot;&gt;macでKeynoteを使っていると、PowerPointが使い難くてたまらない。数ある問題のひとつ、「貼付けたPDFの画質が落ちる」という問題への対処法。せっかくPDFで貼付けているのに、どうしてガビガビにしてしまうのか。液晶プロジェクタで出力するなら高解像度は必要ないが、配布資料の画質が荒いのは困る。&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;使っているプレゼンソフト&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;Keynote&#39;09&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;PowerPoint 2008&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;解決法&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;PowerPointの「環境設定」の「保存オプション」の「解像度の設定」で解像度を高める。「グラフィックファイルの圧縮」を解除する。&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;PDFをソースからコピーし、プレビューで「クリップボードから新規作成」し、PNGで保存する。このときのPNGの解像度が重要。&lt;span style=&quot;background-color: white;&quot;&gt;解像度 300 ピクセル／インチ以上が望ましい。&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;.pngファイルをPowerPointに貼付ける。&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;Keynoteにはめ込んだPDFほどではないが、それなりにクリアになる。&lt;/span&gt;&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://bioinfomemoblog.blogspot.com/feeds/3556349531052364239/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='http://bioinfomemoblog.blogspot.com/2012/06/powerpoint.html#comment-form' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8963258932818536016/posts/default/3556349531052364239'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8963258932818536016/posts/default/3556349531052364239'/><link rel='alternate' type='text/html' href='http://bioinfomemoblog.blogspot.com/2012/06/powerpoint.html' title='PowerPointの低い解像度について'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8963258932818536016.post-3270196970311665364</id><published>2012-06-15T22:31:00.002+09:00</published><updated>2012-06-15T22:31:58.139+09:00</updated><title type='text'>for()ループを入れ子にして検索するより、Rならではの方法で</title><content type='html'>&lt;br /&gt;
IDと数値をもつ表があり、それとは別にIDのリストがあるとする。そのとき、リスト中のIDに対応する数値を表から抽出するにはどうしたらいいだろうか。&lt;br /&gt;
&lt;br /&gt;
Rを使う。&lt;br /&gt;
&lt;br /&gt;
for()ループでIDリストを１つずつ取り出し、そのループの中で更にfor()ループを使って表を１行ずつ取り出し、対応するIDをif()で探すという方法が思い浮かぶ。for()ループを入れ子構造にするやり方だ。方法を下に示す。&lt;br /&gt;
&lt;br /&gt;
この入れ子構造でやってみるとものすごく遅い。２つ目のfor()ループは表の行数マイナス１行分も無駄に動いているわけだから、遅いのも頷ける。でも、perlだったらもっと速くに結果がでるような気がする。どうやらRはループが苦手らしい。&lt;br /&gt;
&lt;br /&gt;
作業効率がとても悪いので、for()ループをひとつ減らして同じ結果を得る方法を考えた。if()で条件検討をせず、セルが一致する行をそのままRっぽく拾う。方法を下に示す。&lt;br /&gt;
&lt;br /&gt;
ここに示す小さなデータではスピードの違いを実感できないが、数千行の表の中から数百のリストに合致する行を得ようとすれば、その違いは雲泥の差。前者ならかけっぱなしで散歩にでも行きたくなるが、後者ならあくびをしている間に終了する。&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
とりあえず、説明用にデータを用意する。&lt;br /&gt;
&lt;br /&gt;
データフレーム（df.1）を用意する。&lt;br /&gt;
&lt;br /&gt;
id1 &amp;lt;- c(&quot;A&quot;,&quot;B&quot;,&quot;C&quot;,&quot;D&quot;,&quot;E&quot;,&quot;F&quot;)&lt;br /&gt;
value1 &amp;lt;- rnorm(6,mean=3,sd=1)&lt;br /&gt;
df1 &amp;lt;- data.frame(id1,value1)&lt;br /&gt;
&lt;br /&gt;
&amp;gt; df1&lt;br /&gt;
&amp;nbsp; id1 &amp;nbsp; value1&lt;br /&gt;
1 &amp;nbsp; A 2.484163&lt;br /&gt;
2 &amp;nbsp; B 1.539250&lt;br /&gt;
3 &amp;nbsp; C 2.773143&lt;br /&gt;
4 &amp;nbsp; D 1.041669&lt;br /&gt;
5 &amp;nbsp; E 2.409677&lt;br /&gt;
6 &amp;nbsp; F 2.532448&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
IDリスト（id2）を用意する。&lt;br /&gt;
&lt;br /&gt;
id2 &amp;lt;- c(&quot;B&quot;,&quot;D&quot;,&quot;E&quot;)&lt;br /&gt;
&lt;br /&gt;
&amp;gt; id2&lt;br /&gt;
[1] &quot;B&quot; &quot;D&quot; &quot;E&quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
入れ子構造のやり方。&lt;br /&gt;
forループを２つ重ねて検索する。&lt;br /&gt;
&lt;br /&gt;
found1 &amp;lt;- df1[0,]&lt;br /&gt;
for (i in 1:length(id2)){&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;for (j in 1:nrow(df1)){&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;if (id2[i]==df1[j,1]){&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;hit1 &amp;lt;- df1[j,]&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;found1 &amp;lt;- rbind(found1,hit1)&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;gt; found1&lt;br /&gt;
&amp;nbsp; id1 &amp;nbsp; value1&lt;br /&gt;
2 &amp;nbsp; B 1.539250&lt;br /&gt;
4 &amp;nbsp; D 1.041669&lt;br /&gt;
5 &amp;nbsp; E 2.409677&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Rの強みを活かすやり方。&lt;br /&gt;
forループをひとつだけにする。&lt;br /&gt;
&lt;br /&gt;
found2 &amp;lt;- df1[0,]&lt;br /&gt;
for(x in 1:length(id2)){&lt;br /&gt;
hit2 &amp;lt;- df1[df1[,1]==id2[x],]&lt;br /&gt;
found2 &amp;lt;- rbind(found2,hit2)&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;gt; found2&lt;br /&gt;
&amp;nbsp; id1 &amp;nbsp; value1&lt;br /&gt;
2 &amp;nbsp; B 1.539250&lt;br /&gt;
4 &amp;nbsp; D 1.041669&lt;br /&gt;
5 &amp;nbsp; E 2.409677&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://bioinfomemoblog.blogspot.com/feeds/3270196970311665364/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='http://bioinfomemoblog.blogspot.com/2012/06/forr.html#comment-form' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8963258932818536016/posts/default/3270196970311665364'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8963258932818536016/posts/default/3270196970311665364'/><link rel='alternate' type='text/html' href='http://bioinfomemoblog.blogspot.com/2012/06/forr.html' title='for()ループを入れ子にして検索するより、Rならではの方法で'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8963258932818536016.post-320943131438949208</id><published>2012-06-11T15:28:00.007+09:00</published><updated>2012-06-12T16:03:24.337+09:00</updated><title type='text'>MEMEの前にリピートをマスク</title><content type='html'>&lt;br /&gt;
&lt;a href=&quot;http://bioinfomemoblog.blogspot.jp/2012/06/macschip-seq.html&quot; target=&quot;_blank&quot;&gt;MEMEを使ってプロモーター中のモチーフ探し&lt;/a&gt;をすると、意味がありそうな、なさそうな、保存性の高いエレメントが多数ヒットすることがある。これらは通常とても長い。ゲノムにはAluなどのリピート配列が多く、それらが解析対象のプロモーター配列セットの中に沢山含まれてしまっているためだ。&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;MEMEでDNAモチーフを探すときは、&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;あらかじめリピートをマスクしたFASTAを用いるべきだろう。&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
リピートのマスキングには、giri（Genetic Information Research Institute）のRepeat Maskingツール「&lt;a href=&quot;http://www.girinst.org/censor/index.php&quot; target=&quot;_blank&quot;&gt;CENSOR&lt;/a&gt;」が使える。&lt;span style=&quot;font-family: inherit;&quot;&gt;生物種（Sequence source）を指定し、Report simple repeatsをチェックし、FASTAを与えて実行すると、リピート部分の塩基を「X」に置き換えたFASTAを返してくれる。もちろん、どのようなリピートがどこにヒットするかも教えてくれる。&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;都合のいいことに、CENSORが返してくれたFASTA（「X」でリピートがマスクされたもの）は、そのままMEMEに与えることができる。&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bioinfomemoblog.blogspot.com/feeds/320943131438949208/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='http://bioinfomemoblog.blogspot.com/2012/06/meme_11.html#comment-form' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8963258932818536016/posts/default/320943131438949208'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8963258932818536016/posts/default/320943131438949208'/><link rel='alternate' type='text/html' href='http://bioinfomemoblog.blogspot.com/2012/06/meme_11.html' title='MEMEの前にリピートをマスク'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8963258932818536016.post-6168532935342839331</id><published>2012-06-07T19:02:00.001+09:00</published><updated>2012-06-07T19:05:01.965+09:00</updated><title type='text'>.wigのtag countをmedianでノーマライズする</title><content type='html'>&lt;br /&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span class=&quot;s1&quot;&gt;&lt;a href=&quot;http://bioinfomemoblog.blogspot.jp/2012/06/macschip-seq.html&quot; target=&quot;_blank&quot;&gt;MACSが出力したwiggle&lt;/a&gt;のtag countや、&lt;a href=&quot;http://bioinfomemoblog.blogspot.jp/2012/06/bamdepth.html&quot; target=&quot;_blank&quot;&gt;samtools mpileup -D&lt;/a&gt;あるいはsamtools depthで得られたdepthを比較解析したいとき、ノーマライズのひとつのやり方として、medianで割るという方法が考えられる。&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span class=&quot;s1&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span class=&quot;s1&quot;&gt;R&lt;/span&gt;を使えば簡単。&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span class=&quot;s1&quot;&gt;wiggle&lt;/span&gt;を読み込む。ヘッダー２行は省く（skip=2）。&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;wig &amp;lt;- read.table(&quot;&amp;lt;in.wig&amp;gt;&quot;,skip=2)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;gt; head(wig)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; V1&amp;nbsp; V2&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;1&amp;nbsp; 1 &amp;nbsp; 3&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;2 11&amp;nbsp; 34&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;3 21&amp;nbsp; 49&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;4 31&amp;nbsp; 65&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;5 41&amp;nbsp; 81&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;6 51 105&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;２列目のデータを、２列目の&lt;span class=&quot;s1&quot;&gt;median&lt;/span&gt;で割った値で置き換える。&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;wig$V2 &amp;lt;- wig$V2/median(wig$V2)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;gt; head(wig)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; V1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; V2&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;1&amp;nbsp; 1 0.007575758&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;2 11 0.085858586&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;3 21 0.123737374&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;4 31 0.164141414&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;5 41 0.204545455&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;6 51 0.265151515&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;小数点以下２桁にする&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;wig$V2 &amp;lt;- round(wig$V2,digits=2)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;gt; head(wig)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; V1 &amp;nbsp; V2&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;1&amp;nbsp; 1 0.01&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;2 11 0.09&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;3 21 0.12&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;4 31 0.16&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;5 41 0.20&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;6 51 0.27&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;まとめてやるなら、&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;wig &amp;lt;- read.table(&quot;&amp;lt;in.wig&amp;gt;&quot;,skip=2)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;wig$V2 &amp;lt;- round(wig$V2/median(wig$V2),digits=2)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;必要に応じて&lt;span class=&quot;s1&quot;&gt;read.table&lt;/span&gt;で書き出したり、プロットしたりする。&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bioinfomemoblog.blogspot.com/feeds/6168532935342839331/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='http://bioinfomemoblog.blogspot.com/2012/06/wigtag-countmedian.html#comment-form' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8963258932818536016/posts/default/6168532935342839331'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8963258932818536016/posts/default/6168532935342839331'/><link rel='alternate' type='text/html' href='http://bioinfomemoblog.blogspot.com/2012/06/wigtag-countmedian.html' title='.wigのtag countをmedianでノーマライズする'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8963258932818536016.post-7060757707203471851</id><published>2012-06-07T18:36:00.004+09:00</published><updated>2012-06-07T18:39:09.012+09:00</updated><title type='text'>IGVの調整によりwiggle等を開けるようにする</title><content type='html'>&lt;br /&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span class=&quot;s1&quot;&gt;IGV&lt;/span&gt;の調整により&lt;span class=&quot;s1&quot;&gt;wiggle&lt;/span&gt;を開けるようにする&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span class=&quot;s1&quot;&gt;MACS&lt;/span&gt;が作成したwiggle（.wig）のヘッダー情報にある染色体名（chrom=）がIGVで用いるアセンブリと一致しない場合、&lt;a href=&quot;http://bioinfomemoblog.blogspot.jp/2012/06/igvwiggle.html&quot; target=&quot;_blank&quot;&gt;wiggleのヘッダーを書き換える&lt;/a&gt;以外に、IGVの設定を調整するという解決策もある。&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;macなら、ホームフォルダに「igv」というフォルダがあり（IGV 2.0のときは不可視化されていた？）、その中の「genomes」に、エイリアスファイルなるものを作って入れてやるだけで良い。&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;詳しい説明はこちら。&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;a href=&quot;http://www.broadinstitute.org/software/igv/LoadData/#aliasfile&quot; target=&quot;_blank&quot;&gt;Creating a Chromosome Name Alias File&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;.wigと染色体名が一致しない問題は、BWA等によるアライメントの時に使用するリファレンスゲノム（.fasta）の染色体名をあらかじめIGVに合わせておくことで回避できるが、様々なソースから得たGFFやBEDなどもまた、染色体名の記述方法が異なる場合がある。その都度書類を書き換えるより、上記のごとくIGVの設定を変更しておくと楽。&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bioinfomemoblog.blogspot.com/feeds/7060757707203471851/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='http://bioinfomemoblog.blogspot.com/2012/06/igvwiggle_07.html#comment-form' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8963258932818536016/posts/default/7060757707203471851'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8963258932818536016/posts/default/7060757707203471851'/><link rel='alternate' type='text/html' href='http://bioinfomemoblog.blogspot.com/2012/06/igvwiggle_07.html' title='IGVの調整によりwiggle等を開けるようにする'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>