<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>R-statistics blog &#187; R tutorial</title>
	<atom:link href="http://www.r-statistics.com/tag/r-tutorial/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.r-statistics.com</link>
	<description>Writing about statistics with R, and open source stuff (software, data, community)</description>
	<lastBuildDate>Mon, 30 Jan 2012 07:45:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>data.frame objects in R (via &#8220;R in Action&#8221;)</title>
		<link>http://www.r-statistics.com/2011/12/data-frame-objects-in-r-via-r-in-action/</link>
		<comments>http://www.r-statistics.com/2011/12/data-frame-objects-in-r-via-r-in-action/#comments</comments>
		<pubDate>Sun, 18 Dec 2011 22:02:04 +0000</pubDate>
		<dc:creator>Tal Galili</dc:creator>
				<category><![CDATA[R]]></category>
		<category><![CDATA[data frames]]></category>
		<category><![CDATA[data.frame]]></category>
		<category><![CDATA[R book]]></category>
		<category><![CDATA[R classes]]></category>
		<category><![CDATA[R in action]]></category>
		<category><![CDATA[R objects]]></category>
		<category><![CDATA[R tutorial]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.r-statistics.com/?p=865</guid>
		<description><![CDATA[The followings introductory post is intended for new users of R.  It deals with R data frames: what they are, and how to create, view, and update them. This is a guest article by Dr. Robert I. Kabacoff, the founder of (one of) the first online R tutorials websites: Quick-R.  Kabacoff has recently published the book &#8221;R [...]]]></description>
			<content:encoded><![CDATA[<div class="socialize-in-content" style="float:right;"><div class="socialize-in-button socialize-in-button-right"><iframe src="http://www.facebook.com/plugins/like.php?href=http://www.r-statistics.com/2011/12/data-frame-objects-in-r-via-r-in-action/&amp;layout=box_count&amp;show_faces=false&amp;width=50&amp;action=like&amp;font=arial&amp;colorscheme=light&amp;height=65" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:50px !important; height:65px;" allowTransparency="true"></iframe></div><div class="socialize-in-button socialize-in-button-right"><g:plusone size="tall" href="http://www.r-statistics.com/2011/12/data-frame-objects-in-r-via-r-in-action/"></g:plusone></div></div><p><strong>The followings introductory post is intended for new users of R.  It deals with R data frames: what they are, and how to create, view, and update them.</strong></p>
<p>This is a guest article by Dr. <a href="http://www.statmethods.net/about/author.html">Robert I. Kabacoff</a>, the founder of (one of) the first online R tutorials websites: <a href="http://www.statmethods.net/interface/index.html">Quick-R</a>.  Kabacoff has recently published the book &#8221;<strong><a href="http://affiliate.manning.com/idevaffiliate.php?id=1205&#038;url=21">R in Action</a></strong>&#8220;, providing a detailed walk-through for the R language based on various examples for illustrating R’s features (data manipulation, statistical methods, graphics, and so on&#8230;)</p>
<p><a href="http://affiliate.manning.com/idevaffiliate.php?id=1205&#038;url=21"><img src="http://www.r-statistics.com/wp-content/uploads/2011/12/kabacoff_cover150.jpg" alt="" title="R in Action cover image" width="150" height="188" class="alignleft size-full wp-image-874" /></a></p>
<p>For readers of this blog, there is a<strong> 38% discount</strong> off <a href="http://affiliate.manning.com/idevaffiliate.php?id=1205&#038;url=21">the &#8220;R in Action&#8221; book</a> (as well as all other eBooks, pBooks and MEAPs at <a href="http://affiliate.manning.com/idevaffiliate.php?id=1205">Manning publishing house</a>), simply by using the code <em><strong>rblogg38 </strong></em>when reaching checkout.</p>
<p>Let us now talk about data frames:<br />
<span id="more-865"></span><br />
<u><br />
<h3>Data Frames</h3>
<p></u><br />
A data frame is more general than a matrix in that different columns can contain different modes of data (numeric, character, and so on). It’s similar to the datasets you’d typically see in SAS, SPSS, and Stata. Data frames are the most common data structure you’ll deal with in R.</p>
<p>The patient dataset in table 1 consists of numeric and character data.</p>
<p><em>Table 1: A patient dataset</em></p>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top" width="67">
<div>
<p>PatientID</p>
</div>
</td>
<td valign="top" width="78">
<div>
<p>AdmDate</p>
</div>
</td>
<td valign="top" width="42">
<div>
<p>Age</p>
</div>
</td>
<td valign="top" width="60">
<div>
<p>Diabetes</p>
</div>
</td>
<td valign="top" width="66">
<div>
<p>Status</p>
</div>
</td>
</tr>
<tr>
<td valign="top" width="67">1</td>
<td valign="top" width="78">10/15/2009</td>
<td valign="top" width="42">25</td>
<td valign="top" width="60">Type1</td>
<td valign="top" width="66">Poor</td>
</tr>
<tr>
<td valign="top" width="67">2</td>
<td valign="top" width="78">11/01/2009</td>
<td valign="top" width="42">34</td>
<td valign="top" width="60">Type2</td>
<td valign="top" width="66">Improved</td>
</tr>
<tr>
<td valign="top" width="67">3</td>
<td valign="top" width="78">10/21/2009</td>
<td valign="top" width="42">28</td>
<td valign="top" width="60">Type1</td>
<td valign="top" width="66">Excellent</td>
</tr>
<tr>
<td valign="top" width="67">4</td>
<td valign="top" width="78">10/28/2009</td>
<td valign="top" width="42">52</td>
<td valign="top" width="60">Type1</td>
<td valign="top" width="66">Poor</td>
</tr>
</tbody>
</table>
<p>Because there are multiple modes of data, you can’t contain this data in a matrix. In this case, a data frame would be the structure of choice.</p>
<p>A data frame is created with the data.frame() function:</p>

<div class="wp_codebox"><table><tr id="p86512"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p865code12"><pre class="rsplus" style="font-family:monospace;">mydata <span style="color: #080;">&lt;-</span> <span style="color: #0000FF; font-weight: bold;">data.<span style="">frame</span></span><span style="color: #080;">&#40;</span>col1, col2, col3,…<span style="color: #080;">&#41;</span></pre></td></tr></table></div>

<p>where <em>col1, col2, col3, </em>… are column vectors of any type (such as character, numeric, or logical). Names for each column can be provided with the names function.</p>
<p>The following listing makes this clear.</p>
<p><strong>Listing 1 Creating a data frame</strong></p>

<div class="wp_codebox"><table><tr id="p86513"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code" id="p865code13"><pre class="rsplus" style="font-family:monospace;"><span style="color: #080;">&gt;</span> patientID <span style="color: #080;">&lt;-</span> <span style="color: #0000FF; font-weight: bold;">c</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">1</span>, <span style="color: #ff0000;">2</span>, <span style="color: #ff0000;">3</span>, <span style="color: #ff0000;">4</span><span style="color: #080;">&#41;</span>
<span style="color: #080;">&gt;</span> age <span style="color: #080;">&lt;-</span> <span style="color: #0000FF; font-weight: bold;">c</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">25</span>, <span style="color: #ff0000;">34</span>, <span style="color: #ff0000;">28</span>, <span style="color: #ff0000;">52</span><span style="color: #080;">&#41;</span>
<span style="color: #080;">&gt;</span> diabetes <span style="color: #080;">&lt;-</span> <span style="color: #0000FF; font-weight: bold;">c</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">&quot;Type1&quot;</span>, <span style="color: #ff0000;">&quot;Type2&quot;</span>, <span style="color: #ff0000;">&quot;Type1&quot;</span>, <span style="color: #ff0000;">&quot;Type1&quot;</span><span style="color: #080;">&#41;</span>
<span style="color: #080;">&gt;</span> status <span style="color: #080;">&lt;-</span> <span style="color: #0000FF; font-weight: bold;">c</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">&quot;Poor&quot;</span>, <span style="color: #ff0000;">&quot;Improved&quot;</span>, <span style="color: #ff0000;">&quot;Excellent&quot;</span>, <span style="color: #ff0000;">&quot;Poor&quot;</span><span style="color: #080;">&#41;</span>
<span style="color: #080;">&gt;</span> patientdata <span style="color: #080;">&lt;-</span> <span style="color: #0000FF; font-weight: bold;">data.<span style="">frame</span></span><span style="color: #080;">&#40;</span>patientID, age, diabetes, status<span style="color: #080;">&#41;</span>
<span style="color: #080;">&gt;</span> patientdata
  patientID age diabetes status
<span style="color: #ff0000;">1</span>         <span style="color: #ff0000;">1</span>  <span style="color: #ff0000;">25</span>    Type1 Poor
<span style="color: #ff0000;">2</span>         <span style="color: #ff0000;">2</span>  <span style="color: #ff0000;">34</span>    Type2 Improved
<span style="color: #ff0000;">3</span>         <span style="color: #ff0000;">3</span>  <span style="color: #ff0000;">28</span>    Type1 Excellent
<span style="color: #ff0000;">4</span>         <span style="color: #ff0000;">4</span>  <span style="color: #ff0000;">52</span>    Type1 Poor</pre></td></tr></table></div>

<p>Each column must have only one mode, but you can put columns of different modes together to form the data frame. Because data frames are close to what analysts typically think of as datasets, we’ll use the terms columns and variables interchangeably when discussing data frames.</p>
<p>There are several ways to identify the elements of a data frame. You can use the subscript notation or you can specify column names. Using the patientdata data frame created earlier, the following listing demonstrates these approaches.</p>
<p><strong>Listing 2 Specifying elements of a data frame</strong></p>

<div class="wp_codebox"><table><tr id="p86514"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code" id="p865code14"><pre class="rsplus" style="font-family:monospace;"><span style="color: #080;">&gt;</span> patientdata<span style="color: #080;">&#91;</span><span style="color: #ff0000;">1</span><span style="color: #080;">:</span><span style="color: #ff0000;">2</span><span style="color: #080;">&#93;</span>
  patientID age
<span style="color: #ff0000;">1</span>         <span style="color: #ff0000;">1</span>  <span style="color: #ff0000;">25</span>
<span style="color: #ff0000;">2</span>         <span style="color: #ff0000;">2</span>  <span style="color: #ff0000;">34</span>
<span style="color: #ff0000;">3</span>         <span style="color: #ff0000;">3</span>  <span style="color: #ff0000;">28</span>
<span style="color: #ff0000;">4</span>         <span style="color: #ff0000;">4</span>  <span style="color: #ff0000;">52</span>
<span style="color: #080;">&gt;</span> patientdata<span style="color: #080;">&#91;</span><span style="color: #0000FF; font-weight: bold;">c</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">&quot;diabetes&quot;</span>, <span style="color: #ff0000;">&quot;status&quot;</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#93;</span>
  diabetes status
<span style="color: #ff0000;">1</span>    Type1 Poor
<span style="color: #ff0000;">2</span>    Type2 Improved
<span style="color: #ff0000;">3</span>    Type1 Excellent 
<span style="color: #ff0000;">4</span>    Type1 Poor
<span style="color: #080;">&gt;</span> patientdata$age    <span style="color: #228B22;">#age variable in the patient data frame</span>
<span style="color: #080;">&#91;</span><span style="color: #ff0000;">1</span><span style="color: #080;">&#93;</span> <span style="color: #ff0000;">25</span> <span style="color: #ff0000;">34</span> <span style="color: #ff0000;">28</span> <span style="color: #ff0000;">52</span></pre></td></tr></table></div>

<p>The $ notation in the third example is used to indicate a particular variable from a given data frame. For example, if you want to cross-tabulate diabetes type by status, you could use the following code:</p>

<div class="wp_codebox"><table><tr id="p86515"><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code" id="p865code15"><pre class="rsplus" style="font-family:monospace;"><span style="color: #080;">&gt;</span> <span style="color: #0000FF; font-weight: bold;">table</span><span style="color: #080;">&#40;</span>patientdata$diabetes, patientdata$status<span style="color: #080;">&#41;</span>
&nbsp;
        Excellent Improved Poor
  Type1         <span style="color: #ff0000;">1</span>        <span style="color: #ff0000;">0</span>    <span style="color: #ff0000;">2</span>
  Type2         <span style="color: #ff0000;">0</span>        <span style="color: #ff0000;">1</span>    <span style="color: #ff0000;">0</span></pre></td></tr></table></div>

<p>It can get tiresome typing patientdata$ at the beginning of every variable name, so shortcuts are available. You can use either the attach() and detach() or with() functions to simplify your code.</p>
<h3>attach, detach, and with</h3>
<p>The attach() function adds the data frame to the R search path. When a variable name is encountered, data frames in the search path are checked in order to locate the variable. Using a sample (mtcars) data frame, you could use the following code to obtain summary statistics for automobile mileage (mpg), and plot this variable against engine displacement (disp), and weight (wt):</p>

<div class="wp_codebox"><table><tr id="p86516"><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="p865code16"><pre class="rsplus" style="font-family:monospace;"><span style="color: #0000FF; font-weight: bold;">summary</span><span style="color: #080;">&#40;</span><span style="color: #CC9900; font-weight: bold;">mtcars</span>$mpg<span style="color: #080;">&#41;</span>
<span style="color: #0000FF; font-weight: bold;">plot</span><span style="color: #080;">&#40;</span><span style="color: #CC9900; font-weight: bold;">mtcars</span>$mpg, <span style="color: #CC9900; font-weight: bold;">mtcars</span>$disp<span style="color: #080;">&#41;</span>
<span style="color: #0000FF; font-weight: bold;">plot</span><span style="color: #080;">&#40;</span><span style="color: #CC9900; font-weight: bold;">mtcars</span>$mpg, <span style="color: #CC9900; font-weight: bold;">mtcars</span>$wt<span style="color: #080;">&#41;</span></pre></td></tr></table></div>

<p>This could also be written as</p>

<div class="wp_codebox"><table><tr id="p86517"><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code" id="p865code17"><pre class="rsplus" style="font-family:monospace;"><span style="color: #0000FF; font-weight: bold;">attach</span><span style="color: #080;">&#40;</span><span style="color: #CC9900; font-weight: bold;">mtcars</span><span style="color: #080;">&#41;</span>
  <span style="color: #0000FF; font-weight: bold;">summary</span><span style="color: #080;">&#40;</span>mpg<span style="color: #080;">&#41;</span>
  <span style="color: #0000FF; font-weight: bold;">plot</span><span style="color: #080;">&#40;</span>mpg, disp<span style="color: #080;">&#41;</span>
  <span style="color: #0000FF; font-weight: bold;">plot</span><span style="color: #080;">&#40;</span>mpg, wt<span style="color: #080;">&#41;</span>
<span style="color: #0000FF; font-weight: bold;">detach</span><span style="color: #080;">&#40;</span><span style="color: #CC9900; font-weight: bold;">mtcars</span><span style="color: #080;">&#41;</span></pre></td></tr></table></div>

<p>The detach() function removes the data frame from the search path. Note that detach() does nothing to the data frame itself. The statement is optional but is good programming practice and should be included routinely.</p>
<p>The limitations with this approach are evident when more than one object can have the same name. Consider the following code:</p>

<div class="wp_codebox"><table><tr id="p86518"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code" id="p865code18"><pre class="rsplus" style="font-family:monospace;"><span style="color: #080;">&gt;</span> mpg <span style="color: #080;">&lt;-</span> <span style="color: #0000FF; font-weight: bold;">c</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">25</span>, <span style="color: #ff0000;">36</span>, <span style="color: #ff0000;">47</span><span style="color: #080;">&#41;</span>
<span style="color: #080;">&gt;</span> <span style="color: #0000FF; font-weight: bold;">attach</span><span style="color: #080;">&#40;</span><span style="color: #CC9900; font-weight: bold;">mtcars</span><span style="color: #080;">&#41;</span>
&nbsp;
The following object<span style="color: #080;">&#40;</span>s<span style="color: #080;">&#41;</span> are masked _by_ ‘.<span style="">GlobalEnv</span>’<span style="color: #080;">:</span> mpg
<span style="color: #080;">&gt;</span> <span style="color: #0000FF; font-weight: bold;">plot</span><span style="color: #080;">&#40;</span>mpg, wt<span style="color: #080;">&#41;</span>
Error <span style="color: #0000FF; font-weight: bold;">in</span> <span style="color: #0000FF; font-weight: bold;">xy.<span style="">coords</span></span><span style="color: #080;">&#40;</span>x, y, xlabel, ylabel, <span style="color: #0000FF; font-weight: bold;">log</span><span style="color: #080;">&#41;</span> <span style="color: #080;">:</span>
  ‘x’ and ‘y’ lengths differ
<span style="color: #080;">&gt;</span> mpg
<span style="color: #080;">&#91;</span><span style="color: #ff0000;">1</span><span style="color: #080;">&#93;</span> <span style="color: #ff0000;">25</span> <span style="color: #ff0000;">36</span> <span style="color: #ff0000;">47</span></pre></td></tr></table></div>

<p>Here we already have an object named mpg in our environment when the mtcars data frame is attached. In such cases, the original object takes precedence, which isn’t what you want. The plot statement fails because mpg has 3 elements and disp has 32 elements. The attach() and detach() functions are best used when you’re analyzing a single data frame and you’re unlikely to have multiple objects with the same name. In any case, be vigilant for warnings that say that objects are being masked.</p>
<p>An alternative approach is to use the with() function. You could write the previous example as</p>

<div class="wp_codebox"><table><tr id="p86519"><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code" id="p865code19"><pre class="rsplus" style="font-family:monospace;"><span style="color: #0000FF; font-weight: bold;">with</span><span style="color: #080;">&#40;</span><span style="color: #CC9900; font-weight: bold;">mtcars</span>, <span style="color: #080;">&#123;</span>
  <span style="color: #0000FF; font-weight: bold;">summary</span><span style="color: #080;">&#40;</span>mpg, disp, wt<span style="color: #080;">&#41;</span>
  <span style="color: #0000FF; font-weight: bold;">plot</span><span style="color: #080;">&#40;</span>mpg, disp<span style="color: #080;">&#41;</span>
  <span style="color: #0000FF; font-weight: bold;">plot</span><span style="color: #080;">&#40;</span>mpg, wt<span style="color: #080;">&#41;</span>
<span style="color: #080;">&#125;</span><span style="color: #080;">&#41;</span></pre></td></tr></table></div>

<p>In this case, the statements within the {} brackets are evaluated with reference to the mtcars data frame. You don’t have to worry about name conflicts here. If there’s only one statement (for example, summary(mpg)), the {} brackets are optional.</p>
<p>The limitation of the with() function is that assignments will only exist within the function brackets. Consider the following:</p>

<div class="wp_codebox"><table><tr id="p86520"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code" id="p865code20"><pre class="rsplus" style="font-family:monospace;"><span style="color: #080;">&gt;</span> <span style="color: #0000FF; font-weight: bold;">with</span><span style="color: #080;">&#40;</span><span style="color: #CC9900; font-weight: bold;">mtcars</span>, <span style="color: #080;">&#123;</span>
   stats <span style="color: #080;">&lt;-</span> <span style="color: #0000FF; font-weight: bold;">summary</span><span style="color: #080;">&#40;</span>mpg<span style="color: #080;">&#41;</span>
   stats
  <span style="color: #080;">&#125;</span><span style="color: #080;">&#41;</span>
   Min. 1st Qu. <span style="">Median</span> Mean 3rd Qu. <span style="">Max</span>.
  <span style="color: #ff0000;">10.40</span> <span style="color: #ff0000;">15.43</span> <span style="color: #ff0000;">19.20</span> <span style="color: #ff0000;">20.09</span> <span style="color: #ff0000;">22.80</span> <span style="color: #ff0000;">33.90</span>
<span style="color: #080;">&gt;</span> stats
Error<span style="color: #080;">:</span> object ‘stats’ not found</pre></td></tr></table></div>

<p>If you need to create objects that will exist outside of the with() construct, use the special assignment operator &lt;&lt;- instead of the standard one (&lt;-). It will save the object to the global environment outside of the with() call. This can be demonstrated with the following code:</p>

<div class="wp_codebox"><table><tr id="p86521"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code" id="p865code21"><pre class="rsplus" style="font-family:monospace;"><span style="color: #080;">&gt;</span> <span style="color: #0000FF; font-weight: bold;">with</span><span style="color: #080;">&#40;</span><span style="color: #CC9900; font-weight: bold;">mtcars</span>, <span style="color: #080;">&#123;</span>
   nokeepstats <span style="color: #080;">&lt;-</span> <span style="color: #0000FF; font-weight: bold;">summary</span><span style="color: #080;">&#40;</span>mpg<span style="color: #080;">&#41;</span>
   keepstats <span style="color: #080;">&lt;&lt;-</span> <span style="color: #0000FF; font-weight: bold;">summary</span><span style="color: #080;">&#40;</span>mpg<span style="color: #080;">&#41;</span>
<span style="color: #080;">&#125;</span><span style="color: #080;">&#41;</span>
<span style="color: #080;">&gt;</span> nokeepstats
Error<span style="color: #080;">:</span> object ‘nokeepstats’ not found
<span style="color: #080;">&gt;</span> keepstats
   Min. 1st Qu. <span style="">Median</span> Mean 3rd Qu. <span style="">Max</span>.
    <span style="color: #ff0000;">10.40</span> <span style="color: #ff0000;">15.43</span> <span style="color: #ff0000;">19.20</span> <span style="color: #ff0000;">20.09</span> <span style="color: #ff0000;">22.80</span> <span style="color: #ff0000;">33.90</span></pre></td></tr></table></div>

<p>Most books on R recommend using with() over attach(). I think that ultimately the choice is a matter of preference and should be based on what you’re trying to achieve and your understanding of the implications.</p>
<h3>Case identifiers</h3>
<p>In the patient data example, patientID is used to identify individuals in the dataset. In R, case identifiers can be specified with a rowname option in the data frame function. For example, the statement</p>

<div class="wp_codebox"><table><tr id="p86522"><td class="line_numbers"><pre>1
2
</pre></td><td class="code" id="p865code22"><pre class="rsplus" style="font-family:monospace;">patientdata <span style="color: #080;">&lt;-</span> <span style="color: #0000FF; font-weight: bold;">data.<span style="">frame</span></span><span style="color: #080;">&#40;</span>patientID, age, diabetes, status,
   <span style="color: #0000FF; font-weight: bold;">row.<span style="">names</span></span><span style="color: #080;">=</span>patientID<span style="color: #080;">&#41;</span></pre></td></tr></table></div>

<p>specifies patientID as the variable to use in labeling cases on various printouts and graphs produced by R.</p>
<h3>Summary</h3>
<p>One of the most challenging tasks in data analysis is data preparation. R provides various structures for holding data and many methods for importing data from both keyboard and external sources. One of those structures is data frames, which we covered here. Your ability to specify elements of these structures via the bracket notation is particularly important in selecting, subsetting, and transforming data.</p>
<p>R offers a wealth of functions for accessing external data. This includes data from flat files, web files, statistical packages, spreadsheets, and databases. Note that you can also export data from R into these external formats. We showed you how to use either the attach() and detach() or with() functions to simplify your code.</p>
<p><em>This article first appeared as chapter 2.2.4 from the &#8220;<a href="http://affiliate.manning.com/idevaffiliate.php?id=1205&#038;url=21">R in action</a><strong>&#8220;</strong> book, and is published with permission from <a href="http://affiliate.manning.com/idevaffiliate.php?id=1205">Manning publishing house</a>.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.r-statistics.com/2011/12/data-frame-objects-in-r-via-r-in-action/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>A nice link: &#8220;Some hints for the R beginner&#8221;</title>
		<link>http://www.r-statistics.com/2010/03/nice-link-some-hints-for-the-r-beginner/</link>
		<comments>http://www.r-statistics.com/2010/03/nice-link-some-hints-for-the-r-beginner/#comments</comments>
		<pubDate>Sun, 07 Mar 2010 20:47:31 +0000</pubDate>
		<dc:creator>Tal Galili</dc:creator>
				<category><![CDATA[R]]></category>
		<category><![CDATA[R links]]></category>
		<category><![CDATA[hints]]></category>
		<category><![CDATA[link]]></category>
		<category><![CDATA[r help]]></category>
		<category><![CDATA[r tips]]></category>
		<category><![CDATA[R tutorial]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.r-statistics.com/?p=189</guid>
		<description><![CDATA[Patrick Burns just posted to the mailing list the following massage: There is now a document called &#8220;Some hints for the R beginner&#8221; whose purpose is to get people up and running with R as quickly as possible. Direct access to it is: http://www.burns-stat.com/pages/Tutor/hints_R_begin.html JRR Tolkien wrote a story (sans hobbits) called &#8216;Leaf by Niggle&#8217; [...]]]></description>
			<content:encoded><![CDATA[<div class="socialize-in-content" style="float:right;"><div class="socialize-in-button socialize-in-button-right"><iframe src="http://www.facebook.com/plugins/like.php?href=http://www.r-statistics.com/2010/03/nice-link-some-hints-for-the-r-beginner/&amp;layout=box_count&amp;show_faces=false&amp;width=50&amp;action=like&amp;font=arial&amp;colorscheme=light&amp;height=65" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:50px !important; height:65px;" allowTransparency="true"></iframe></div><div class="socialize-in-button socialize-in-button-right"><g:plusone size="tall" href="http://www.r-statistics.com/2010/03/nice-link-some-hints-for-the-r-beginner/"></g:plusone></div></div><p>Patrick Burns just posted to the mailing list the following massage:</p>
<blockquote><p>There is now a document called &#8220;Some hints for the R beginner&#8221; whose purpose is to get people up and running with R as quickly as possible.</p>
<p>Direct access to it is:<br />
<a href="http://www.burns-stat.com/pages/Tutor/hints_R_begin.html">http://www.burns-stat.com/pages/Tutor/hints_R_begin.html</a></p>
<p>JRR Tolkien wrote a story (sans hobbits) called &#8216;Leaf by Niggle&#8217; that has always resonated with me.  I offer you an imperfect, incomplete tree (but my roof is intact).</p>
<p>Suggestions for improvements are encouraged.</p></blockquote>
<p>And here is the link tree for the document (for your easy reviewing of the offered content) :</p>
<p><span id="more-189"></span></p>
<p><strong>This page has several sections, they can be put into the four categories: General, Objects, Actions, Help.</strong></p>
<p><strong>General<br />
<a href="http://www.burns-stat.com/pages/Tutor/hints_R_begin.html#intro">Introduction </a><br />
<a href="http://www.burns-stat.com/pages/Tutor/hints_R_begin.html#blankscreen">Blank screen syndrome </a><br />
<a href="http://www.burns-stat.com/pages/Tutor/hints_R_begin.html#langs">Misconceptions because of a previous language </a><br />
<a href="http://www.burns-stat.com/pages/Tutor/hints_R_begin.html#compenv">Helpful computer environments </a><br />
<a href="http://www.burns-stat.com/pages/Tutor/hints_R_begin.html#jargon">R vocabulary </a><br />
<a href="http://www.burns-stat.com/pages/Tutor/hints_R_begin.html#epilogue">Epilogue </a></strong></p>
<p><strong>Objects<br />
<a href="http://www.burns-stat.com/pages/Tutor/hints_R_begin.html#keyobjects">Key objects </a><br />
<a href="http://www.burns-stat.com/pages/Tutor/hints_R_begin.html#readingdata">Reading data into R </a><br />
<a href="http://www.burns-stat.com/pages/Tutor/hints_R_begin.html#seeingobjects">Seeing objects </a><br />
<a href="http://www.burns-stat.com/pages/Tutor/hints_R_begin.html#savingobjects">Saving objects </a><br />
<a href="http://www.burns-stat.com/pages/Tutor/hints_R_begin.html#magic">Magic functions, magic objects </a><br />
<a href="http://www.burns-stat.com/pages/Tutor/hints_R_begin.html#filetypes">Some file types </a><br />
<a href="http://www.burns-stat.com/pages/Tutor/hints_R_begin.html#packages">Packages </a></p>
<p>Actions<br />
<a href="http://www.burns-stat.com/pages/Tutor/hints_R_begin.html#startup">What happens at R startup </a><br />
<a href="http://www.burns-stat.com/pages/Tutor/hints_R_begin.html#keyactions">Key actions </a><br />
<a href="http://www.burns-stat.com/pages/Tutor/hints_R_begin.html#errors">Errors and such </a><br />
<a href="http://www.burns-stat.com/pages/Tutor/hints_R_begin.html#graphics">Graphics </a><br />
<a href="http://www.burns-stat.com/pages/Tutor/hints_R_begin.html#vectorize">Vectorization </a><br />
<a href="http://www.burns-stat.com/pages/Tutor/hints_R_begin.html#makemistakes">Make mistakes on purpose </a></p>
<p></strong></p>
<p><strong>Help<br />
<a href="http://www.burns-stat.com/pages/Tutor/hints_R_begin.html#readhelp">How to read a help file </a><br />
<a href="http://www.burns-stat.com/pages/Tutor/hints_R_begin.html#search">Searching for functionality </a><br />
<a href="http://www.burns-stat.com/pages/Tutor/hints_R_begin.html#documents">Some other documents </a><br />
<a href="http://www.burns-stat.com/pages/Tutor/hints_R_begin.html#Rhelp">R-help mailing list </a></strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.r-statistics.com/2010/03/nice-link-some-hints-for-the-r-beginner/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

