<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> <title> document_view — bioconductor.org </title> <base href="" /> <meta name="generator" content="Plone - http://plone.org" /> <meta content="sfadmin" name="DC.creator" /> <meta content="2006-10-10 13:25:02" name="DC.date.created" /> <meta content="2006-10-10 13:25:02" name="DC.date.modified" /> <meta content="Document" name="DC.type" /> <meta content="text/plain" name="DC.format" /> <!-- Basic crude style for Netscape4.x - This can be removed if you don't want the special NS4 look - it will still work, just be plain text instead. Column layout for Netscape4.x included --> <link rel="Stylesheet" type="text/css" href="../../../../../ploneNS4.css" /> <!-- Column style sheet. --> <style type="text/css" media="screen"><!-- @import url(http://bioconductor.org/ploneColumns.css); --></style> <!-- Main style sheets for CSS2 capable browsers --> <style type="text/css" media="screen"><!-- @import url(http://bioconductor.org/plone.css); --></style> <!-- Old style sheet from Plone 1.0, remove tal:condition="nothing" if you need to use the old styles. Will be removed in Plone 2.1. --> <!-- Alternate style sheets for the bigger/smaller text switcher --> <link rel="alternate stylesheet" type="text/css" media="screen" href="../../../../../ploneTextSmall.css" title="Small Text" /> <link rel="alternate stylesheet" type="text/css" media="screen" href="../../../../../ploneTextLarge.css" title="Large Text" /> <!-- Style sheet used for printing --> <link rel="stylesheet" type="text/css" media="print" href="../../../../../plonePrint.css" /> <!-- Style sheet used for presentations (Opera is the only browser supporting this at the moment) --> <link rel="stylesheet" type="text/css" media="projection" href="../../../../../plonePresentation.css" /> <!-- Internet Explorer CSS Fixes --> <!--[if IE]> <style type="text/css" media="all">@import url(http://bioconductor.org/ploneIEFixes.css);</style> <![endif]--> <!-- Custom style sheet if available --> <style type="text/css" media="all"><!-- @import url(http://bioconductor.org/ploneCustom.css); --></style> <link rel="shortcut icon" href="../../../../../favicon.ico" type="image/x-icon" /> <link rel="search" href="../../../../../search_form" title="Search this site" /> <link rel="up" href="../BasicR.1" title="Up one level" /> <!-- Disable IE6 image toolbar --> <meta http-equiv="imagetoolbar" content="no" /> <!-- A slot where you can insert CSS in the header from a template --> <!-- min-width support for IE via Javascript, required for tableless --> <!--[if IE]> <script type="text/javascript" src="http://bioconductor.org/plone_minwidth.js"></script> <![endif]--> <!-- A slot where you can insert elements in the header from a template --> <!-- A slot where you can insert javascript in the header from a template --> <!-- Common Plone ECMAScripts --> <!-- Pull-down ECMAScript menu, only active if logged in --> <!-- old google analytics here --> <!-- Define dynamic server-side variables for javascripts in this one --> <script type="text/javascript" src="../../../../../plone_javascript_variables.js"> </script> <script type="text/javascript" src="../../../../../plone_javascripts.js"> </script> <!-- Old JS from Plone 1.0, remove tal:condition="nothing" if you need to use the old pop-ups. Will be removed in Plone 2.1 --> </head> <body class="section-workshops"> <div id="visual-portal-wrapper"> <div id="portal-top"> <a href="basicr.R#documentContent" class="hiddenStructure">Skip to content.</a> <h1 id="portal-logo"> <a href="../../../../../index.html">bioconductor.org</a> </h1> <div id="portal-slogan"><p>Bioconductor is an open source and open development software project<br /> for the analysis and comprehension of genomic data.</p></div> <h5 class="hiddenStructure">Sections</h5> <ul id="portal-globalnav"><li id="portaltab-index_html" class="plain"><a href="../../../../../index.html" accesskey="t">Home</a></li><li id="portaltab-GettingStarted" class="plain"><a href="../../../../../GettingStarted" accesskey="t">Getting Started</a></li><li id="portaltab-overview" class="plain"><a href="../../../../../overview" accesskey="t">Overview</a></li><li id="portaltab-download" class="plain"><a href="../../../../../download" accesskey="t">Downloads</a></li><li id="portaltab-docs" class="plain"><a href="../../../../../docs" accesskey="t">Documentation</a></li><li id="portaltab-biocpub" class="plain"><a href="../../../../../pub" accesskey="t">Publications</a></li><li id="portaltab-workshops" class="selected"><a href="../../../../../workshops" accesskey="t">Workshops</a></li><li id="portaltab-cabig" class="plain"><a href="http://wiki.fhcrc.org/caBioc" accesskey="t">caBIG</a></li></ul> </div> <div class="visualClear"></div> <!-- The wrapper div. It contains the three columns. --> <div id="portal-columns" class="visualColumnHideNone"> <!-- start of the main and left columns --> <div id="visual-column-wrapper"> <!-- start of main content block --> <div id="portal-column-content" class="topmargin1"> <div id="content" class=""> <div class="documentContent" id="region-content"> <a name="documentContent"></a> <h1 class="documentFirstHeading">basicr.R</h1> <div class="documentDescription"></div> <div class="plain"> <p>################################################### ### chunk number 1: lkcon ################################################### x <- c(1,2,3,4) x<a href="#ref2">[2]</a> y <- c(5,6,7,8) y[c(2,3)] m <- cbind(x,y) m m[,"x"]</p> <p>################################################### ### chunk number 2: lkna ################################################### names(x) <- c("a", "b", "c", "d") x["b"] rownames(m) <- LETTERS<a href="#ref1:4">[1:4]</a> m m["A", "y"]</p> <p>################################################### ### chunk number 3: lklit ################################################### litdf <- data.frame(samp1=c(33,22,12),samp2=c(44,111,13)) rownames(litdf) <- c("CRP", "BRCA1", "HOXA") litdf litdf["CRP",] litdf[,"samp1"] litdf["HOXA", "samp2"]</p> <p>################################################### ### chunk number 4: lksel ################################################### x y keep <- c(TRUE, TRUE, FALSE, FALSE, TRUE) x<a href="#refkeep">[keep]</a> x[y>6] which(y>6)</p> <p>################################################### ### chunk number 5: lkoth ################################################### gender <- factor(c("M", "M", "F", "F")) gender season <- ordered(c("spring", "summer", "fall", "winter"), levels=c("spring", "summer", "fall", "winter")) season df <- data.frame(m,gender,season) df</p> <p>################################################### ### chunk number 6: acc ################################################### df df$gender df["B",] z <- "season" df[<a href="#refz">[z]</a>]</p> <p>################################################### ### chunk number 7: mkdf2 ################################################### df2 <- data.frame(x=c(2,3,4,5), z=c(1,6,7,8))</p> <p>################################################### ### chunk number 8: lkm1 ################################################### df df2 merge(df,df2)</p> <p>################################################### ### chunk number 9: mkdf3 ################################################### merge(df,df2,all=TRUE)</p> <p>################################################### ### chunk number 10: lklist ################################################### l1 <- list(df, x=x, fundem=mean) l1</p> <p>################################################### ### chunk number 11: dosp ################################################### dx <- c("ALL", "ALL", "AML", "AML", "ALL", "ALL", "ALL", "AML") ddr1 <- c(12.2, 13.1, 7.2, 6.4, 14.2, 15.3, 9.2, 10.0) split(ddr1,dx)</p> <p>################################################### ### chunk number 12: lkl ################################################### l1[<a href="basicr.R#ref1">[1]</a>] l1$x l1$fund</p> <p>################################################### ### chunk number 13: lkran ################################################### table(rpois(1000, 3)) table(rbinom(1000,5,.5)) sd(rnorm(1000,0,.4)) sd(rnorm(1000,0,.4)) set.seed(1234) sd(rnorm(1000,0,.4)) sd(rnorm(1000,0,.4)) set.seed(1234) sd(rnorm(1000,0,.4))</p> <p>################################################### ### chunk number 14: lkfun ################################################### myfun1 <- function(x,y) { x+3*y } myfun1(2,3)</p> <p>################################################### ### chunk number 15: lkfun2 ################################################### myfun1(2,c(3,4,5,6))</p> <p>################################################### ### chunk number 16: lkb ################################################### 4 <em> c(2,3,4,5) c(2,3) </em> c(4,5,6)</p> <p>################################################### ### chunk number 17: lkit ################################################### for (i in 1:2) print(i,season<a href="basicr.R#refi">[i]</a>) for (i in 1:3) print(l1<a href="basicr.R#refi">[i]</a>) for (s in season) print(s) for (s in as.character(season)) print(s)</p> <p>################################################### ### chunk number 18: lkap ################################################### m apply(m,1,sum) apply(m,2,"^",3)</p> <p>################################################### ### chunk number 19: eval=FALSE ################################################### ## date1 <- date()</p> <p>################################################### ### chunk number 20: doitran ################################################### set.seed(1234) sink(file="sink1.txt") rnorm(5)</p> <p>################################################### ### chunk number 21: eval=FALSE ################################################### ## sink() ## readLines("sink1.txt")</p> <p>################################################### ### chunk number 22: eval=FALSE ################################################### ## length(letters)</p> <p>################################################### ### chunk number 23: eval=FALSE ################################################### ## length(letters==LETTERS)</p> <p>################################################### ### chunk number 24: eval=FALSE ################################################### ## all(letters==tolower(LETTERS))</p> <p>################################################### ### chunk number 25: eval=FALSE ################################################### ## which( letters %in% c("a", "d") )</p> <p>################################################### ### chunk number 26: eval=FALSE ################################################### ## which( c("a", "d") %in% letters )</p> <p>################################################### ### chunk number 27: eval=FALSE ################################################### ## letters[ LETTERS > "W" ]</p> <p>################################################### ### chunk number 28: eval=FALSE ################################################### ## letters[ !LETTERS > "C" ]</p> <p>################################################### ### chunk number 29: eval=FALSE ################################################### ## sum(LETTERS > "c")</p> <p>################################################### ### chunk number 30: eval=FALSE ################################################### ## seq(1,20,3)</p> <p>################################################### ### chunk number 31: eval=FALSE ################################################### ## round(mean(rnorm(1000)),2)</p> <p>################################################### ### chunk number 32: eval=FALSE ################################################### ## mean(rexp(1000,10))</p> <p>################################################### ### chunk number 33: dopoi ################################################### kp <- rpois(100,5) table(kp) bp <- rbinom(100,4,.3) table(bp) table(bp, kp) cols <- sample(c("green", "blue"), replace=TRUE, size=100) table(cols,kp)</p> <p>################################################### ### chunk number 34: domat ################################################### x <- matrix(1:10,nr=10,nc=4) x</p> <p>################################################### ### chunk number 35: dodat ################################################### data(iris3) dim(iris3) dim(iris3<a href="basicr.R#ref,,1">[,,1]</a>)</p> <p>################################################### ### chunk number 36: doex ################################################### expand.grid(c("M", "F"), c("trt", "control"))</p> <p>################################################### ### chunk number 37: eval=FALSE ################################################### ## dim(cbind(x,x)) ## x + 4 ## x + x ## 2 <em> x ## x / c(2,3) ## x + x<a href="basicr.R#ref,-1">[,-1]</a> ## t(x) %</em>% x ## row(x) ## nrow(x) ## x[ x<a href="basicr.R#ref,3">[,3]</a> > 5, ]</p> </div> <div class="discussion"> </div> </div> </div> </div> <!-- end of main content block --> <!-- start of the left (by default at least) column --> <div id="portal-column-one"> <div class="visualPadding"> <br><br><br> <!-- disabled left slot image <img tal:replace="structure nocall:here/pict.jpg" /> --> <div class="portlet" id="portlet-navigation-tree"> <div> <h5>Navigation</h5> <div class="portletBody"> <div class="portletContent odd"> <a href="../../../../../GettingStarted/index.html" accesskey="n" class="navItem navLevel1" title=""> <!-- Disable Folder icon <img src="" height="16" width="16" alt="" class="navIcon" tal:condition="not:isAnon" tal:attributes="src python:portal_url+'/'+sibling.getIcon(1); title sibling/Type;" /> --> <span class="navItemText">Getting Started</span> </a> <a href="../../../../../overview/index.html" accesskey="n" class="navItem navLevel1" title=""> <!-- Disable Folder icon <img src="" height="16" width="16" alt="" class="navIcon" tal:condition="not:isAnon" tal:attributes="src python:portal_url+'/'+sibling.getIcon(1); title sibling/Type;" /> --> <span class="navItemText">Overview</span> </a> <a href="../../../../../download/index.html" accesskey="n" class="navItem navLevel1" title=""> <!-- Disable Folder icon <img src="" height="16" width="16" alt="" class="navIcon" tal:condition="not:isAnon" tal:attributes="src python:portal_url+'/'+sibling.getIcon(1); title sibling/Type;" /> --> <span class="navItemText">Downloads</span> </a> <a href="../../../../../docs/index.html" accesskey="n" class="navItem navLevel1" title=""> <!-- Disable Folder icon <img src="" height="16" width="16" alt="" class="navIcon" tal:condition="not:isAnon" tal:attributes="src python:portal_url+'/'+sibling.getIcon(1); title sibling/Type;" /> --> <span class="navItemText">Documentation</span> </a> <a href="../../../../../pub/index.html" accesskey="n" class="navItem navLevel1" title=""> <!-- Disable Folder icon <img src="" height="16" width="16" alt="" class="navIcon" tal:condition="not:isAnon" tal:attributes="src python:portal_url+'/'+sibling.getIcon(1); title sibling/Type;" /> --> <span class="navItemText">Publications</span> </a> <a href="../../../../index.html" accesskey="n" class="navItem navLevel1" title=""> <!-- Disable Folder icon <img src="" height="16" width="16" alt="" class="navIcon" tal:condition="not:isAnon" tal:attributes="src python:portal_url+'/'+sibling.getIcon(1); title sibling/Type;" /> --> <span class="navItemText">Workshops</span> </a> <a href="../../../../2010/index.html" accesskey="n" class="navItem navLevel2" title=""> <!-- Disable Folder icon <img src="" height="16" width="16" alt="" class="navIcon" tal:condition="not:isAnon" tal:attributes="src python:portal_url+'/'+sibling.getIcon(1); title sibling/Type;" /> --> <span class="navItemText">2010</span> </a> <a href="../../../../2009/index.html" accesskey="n" class="navItem navLevel2" title=""> <!-- Disable Folder icon <img src="" height="16" width="16" alt="" class="navIcon" tal:condition="not:isAnon" tal:attributes="src python:portal_url+'/'+sibling.getIcon(1); title sibling/Type;" /> --> <span class="navItemText">2009</span> </a> <a href="../../../../2008/index.html" accesskey="n" class="navItem navLevel2" title=""> <!-- Disable Folder icon <img src="" height="16" width="16" alt="" class="navIcon" tal:condition="not:isAnon" tal:attributes="src python:portal_url+'/'+sibling.getIcon(1); title sibling/Type;" /> --> <span class="navItemText">2008</span> </a> <a href="../../../../2007/index.html" accesskey="n" class="navItem navLevel2" title=""> <!-- Disable Folder icon <img src="" height="16" width="16" alt="" class="navIcon" tal:condition="not:isAnon" tal:attributes="src python:portal_url+'/'+sibling.getIcon(1); title sibling/Type;" /> --> <span class="navItemText">2007</span> </a> <a href="../../../index.html" accesskey="n" class="navItem navLevel2" title=""> <!-- Disable Folder icon <img src="" height="16" width="16" alt="" class="navIcon" tal:condition="not:isAnon" tal:attributes="src python:portal_url+'/'+sibling.getIcon(1); title sibling/Type;" /> --> <span class="navItemText">2006</span> </a> <a href="../../index.html" accesskey="n" class="navItem navLevel3" title=""> <!-- Disable Folder icon <img src="" height="16" width="16" alt="" class="navIcon" tal:condition="not:isAnon" tal:attributes="src python:portal_url+'/'+sibling.getIcon(1); title sibling/Type;" /> --> <span class="navItemText">R/Bioc Intro Course - October</span> </a> <a href="../index.html" accesskey="n" class="navItem navLevel4" title=""> <!-- Disable Folder icon <img src="" height="16" width="16" alt="" class="navIcon" tal:condition="not:isAnon" tal:attributes="src python:portal_url+'/'+sibling.getIcon(1); title sibling/Type;" /> --> <span class="navItemText">labs</span> </a> <a href="../cDNA/index.html" accesskey="n" class="navItem navLevel5" title=""> <!-- Disable Folder icon <img src="" height="16" width="16" alt="" class="navIcon" tal:condition="not:isAnon" tal:attributes="src python:portal_url+'/'+sibling.getIcon(1); title sibling/Type;" /> --> <span class="navItemText">cDNA (Two Color) Microarray</span> </a> <a href="index.html" accesskey="n" class="navItem navLevel5 currentNavItem" title=""> <!-- Disable Folder icon <img src="" height="16" width="16" alt="" class="navIcon" tal:condition="not:isAnon" tal:attributes="src python:portal_url+'/'+sibling.getIcon(1); title sibling/Type;" /> --> <span class="navItemText">BasicR</span> </a> <a href="../../../BioC2006/index.html" accesskey="n" class="navItem navLevel3" title=""> <!-- Disable Folder icon <img src="" height="16" width="16" alt="" class="navIcon" tal:condition="not:isAnon" tal:attributes="src python:portal_url+'/'+sibling.getIcon(1); title sibling/Type;" /> --> <span class="navItemText">BioC2006</span> </a> <a href="../../../aucklandwksp/index.html" accesskey="n" class="navItem navLevel3" title=""> <!-- Disable Folder icon <img src="" height="16" width="16" alt="" class="navIcon" tal:condition="not:isAnon" tal:attributes="src python:portal_url+'/'+sibling.getIcon(1); title sibling/Type;" /> --> <span class="navItemText">Workshops on S, R and Bioconductor</span> </a> <a href="../../../biocintro_april/index.html" accesskey="n" class="navItem navLevel3" title="April Intro R/Bioc Course at FHCRC"> <!-- Disable Folder icon <img src="" height="16" width="16" alt="" class="navIcon" tal:condition="not:isAnon" tal:attributes="src python:portal_url+'/'+sibling.getIcon(1); title sibling/Type;" /> --> <span class="navItemText">R/Bioc Intro Course</span> </a> <a href="../../../rforbioinformatics/index.html" accesskey="n" class="navItem navLevel3" title="Course materials. The course took place at FHCRC Seattle in January 2006"> <!-- Disable Folder icon <img src="" height="16" width="16" alt="" class="navIcon" tal:condition="not:isAnon" tal:attributes="src python:portal_url+'/'+sibling.getIcon(1); title sibling/Type;" /> --> <span class="navItemText">R for Bioinformatics</span> </a> <a href="../../../../2005/index.html" accesskey="n" class="navItem navLevel2" title=""> <!-- Disable Folder icon <img src="" height="16" width="16" alt="" class="navIcon" tal:condition="not:isAnon" tal:attributes="src python:portal_url+'/'+sibling.getIcon(1); title sibling/Type;" /> --> <span class="navItemText">2005</span> </a> <a href="../../../../2004/index.html" accesskey="n" class="navItem navLevel2" title=""> <!-- Disable Folder icon <img src="" height="16" width="16" alt="" class="navIcon" tal:condition="not:isAnon" tal:attributes="src python:portal_url+'/'+sibling.getIcon(1); title sibling/Type;" /> --> <span class="navItemText">2004</span> </a> <a href="../../../../2003/index.html" accesskey="n" class="navItem navLevel2" title=""> <!-- Disable Folder icon <img src="" height="16" width="16" alt="" class="navIcon" tal:condition="not:isAnon" tal:attributes="src python:portal_url+'/'+sibling.getIcon(1); title sibling/Type;" /> --> <span class="navItemText">2003</span> </a> <a href="../../../../2002/index.html" accesskey="n" class="navItem navLevel2" title="Workshops and courses 2002"> <!-- Disable Folder icon <img src="" height="16" width="16" alt="" class="navIcon" tal:condition="not:isAnon" tal:attributes="src python:portal_url+'/'+sibling.getIcon(1); title sibling/Type;" /> --> <span class="navItemText">2002</span> </a> <a href="../../../../../developers/index.html" accesskey="n" class="navItem navLevel1" title=""> <!-- Disable Folder icon <img src="" height="16" width="16" alt="" class="navIcon" tal:condition="not:isAnon" tal:attributes="src python:portal_url+'/'+sibling.getIcon(1); title sibling/Type;" /> --> <span class="navItemText">Developers</span> </a> <a href="../../../../../News/index.html" accesskey="n" class="navItem navLevel1" title="BioC Project News"> <!-- Disable Folder icon <img src="" height="16" width="16" alt="" class="navIcon" tal:condition="not:isAnon" tal:attributes="src python:portal_url+'/'+sibling.getIcon(1); title sibling/Type;" /> --> <span class="navItemText">News</span> </a> </div> </div> </div> </div> </div> </div> <!-- end of the left (by default at least) column --> </div> <!-- end of the main and left columns --> <!-- start of right (by default at least) column --> <div id="portal-column-two"> <div class="visualPadding"> <div> <!-- The Related Items box --> <script type="text/javascript" src="plonesearchbox_utils.js"> </script> <div class="portlet"> <!-- <h5 i18n:translate="searchbox_title">Search Box</h5> --> <div class="portletBody"> <form name="searchbox_form" id="searchbox_form" method="post" onsubmit="return process()" action="http://bioconductor.org/workshops/2006/biocintro_oct/labs/BasicR/redirectToUrl" target="_blank"> <div class="portletContent odd"> <div id="searchbox_fields"> <input type="text" name="toSearch" id="toSearch" size="22" /> </div> <select name="choice" id="choice" onchange="return generateForm();" style="margin: 3px 0px 0px 0px;"> <option value="http://bioconductor.org/workshops/2006/biocintro_oct/labs/BasicR/basicr.R/search?SearchableText=" id="search_portal">In this site</option> <option value="http://bioconductor.org/workshops/2006/biocintro_oct/labs/BasicR/basicr.R/search?path=/Plones/rgentlem/bioconductor/workshops/2006/biocintro_oct/labs/BasicR/basicr.R&SearchableText=" id="search_rubric">In this folder</option> <option value="http://google.com/search?sitesearch=www.bioconductor.org&q=%(text)s">Google this site</option> </select> <input class="context searchButton" type="submit" value="Search" style="margin: 3px;" /> </div> <!-- <div class="portletContent odd"> <input class="context searchButton" type="submit" value="Search" style="margin: 3px;" i18n:attributes="value"/> </div> <div class="portletContent even"> <a href="" tal:attributes="href string:${portal_url}/search_form" i18n:translate="advanced_search_link">Advanced search</a> </div> --> </form> <script type="text/javascript"> <!-- /*in case the first choice of the combobox is an url with several fields*/ clearForm(); generateForm(); --> </script> </div> </div> </div> <div class="portlet" id="portlet-news"> <h5>News</h5> <div class="portletBody"> <div class="portletContent odd"> <div class="portletDetails"> <a href="../../../../../News/2009-10-28-Release-2.5" class="date" title="BioC 2.5 Released">2009-10-26</a> <p> BioC 2.5, consisting of 352 packages and designed to work with R 2.10.z, was released today. </p> </div> </div> <div class="portletContent even"> <div class="portletDetails"> <a href="../../../../../News/RinNYT" class="date" title="Print Media Recognition">2009-01-07</a> <p> R, the open source platform used by Bioconductor, featured in a series of articles in the New York Times. </p> </div> </div> <div class="portletContent odd"> <a href="../../../../../news" class="portletMore"> More... </a> </div> </div> </div> </div> </div> <!-- end of the right (by default at least) column --> </div> <!-- end column wrapper --> <div class="visualClear"></div> <hr class="netscape4" /> <div id="portal-footer"> © 2003-2009 BioConductor. All Rights Reserved. <script type="text/javascript"> var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E")); </script> <script type="text/javascript"> try{ var pageTracker = _gat._getTracker("UA-357281-1"); pageTracker._trackPageview(); } catch(err) {} </script> </div> </div> </body> </html>