<!DOCTYPE html>
<!-- Generated by pkgdown: do not edit by hand --><html lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"><meta name="description" content="Use to convert between simple versions of several capture history data.frame formats -- &amp;#8220;individual&amp;#8221;, &amp;#8220;frequency&amp;#8221;, &amp;#8220;event&amp;#8221;, &amp;#8220;MARK&amp;#8221;, and &amp;#8220;RMark&amp;#8221;. The primary use is to convert to the &amp;#8220;individual&amp;#8221; format for use in capHistSum."><title>Convert between capture history data.frame formats. — capHistConvert • FSA</title><!-- favicons --><link rel="icon" type="image/png" sizes="16x16" href="../favicon-16x16.png"><link rel="icon" type="image/png" sizes="32x32" href="../favicon-32x32.png"><link rel="apple-touch-icon" type="image/png" sizes="180x180" href="../apple-touch-icon.png"><link rel="apple-touch-icon" type="image/png" sizes="120x120" href="../apple-touch-icon-120x120.png"><link rel="apple-touch-icon" type="image/png" sizes="76x76" href="../apple-touch-icon-76x76.png"><link rel="apple-touch-icon" type="image/png" sizes="60x60" href="../apple-touch-icon-60x60.png"><script src="../deps/jquery-3.6.0/jquery-3.6.0.min.js"></script><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"><link href="../deps/bootstrap-5.2.2/bootstrap.min.css" rel="stylesheet"><script src="../deps/bootstrap-5.2.2/bootstrap.bundle.min.js"></script><!-- Font Awesome icons --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/all.min.css" integrity="sha256-mmgLkCYLUQbXn0B1SRqzHar6dCnv9oZFPEC1g1cwlkk=" crossorigin="anonymous"><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/v4-shims.min.css" integrity="sha256-wZjR52fzng1pJHwx4aV2AO3yyTOXrcDW7jBpJtTwVxw=" crossorigin="anonymous"><!-- bootstrap-toc --><script src="https://cdn.jsdelivr.net/gh/afeld/bootstrap-toc@v1.0.1/dist/bootstrap-toc.min.js" integrity="sha256-4veVQbu7//Lk5TSmc7YV48MxtMy98e26cf5MrgZYnwo=" crossorigin="anonymous"></script><!-- headroom.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/headroom.min.js" integrity="sha256-AsUX4SJE1+yuDu5+mAVzJbuYNPHj/WroHuZ8Ir/CkE0=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/jQuery.headroom.min.js" integrity="sha256-ZX/yNShbjqsohH1k95liqY9Gd8uOiE1S4vZc+9KQ1K4=" crossorigin="anonymous"></script><!-- clipboard.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.6/clipboard.min.js" integrity="sha256-inc5kl9MA1hkeYUt+EC3BhlIgyp/2jDIyBLS6k3UxPI=" crossorigin="anonymous"></script><!-- search --><script src="https://cdnjs.cloudflare.com/ajax/libs/fuse.js/6.4.6/fuse.js" integrity="sha512-zv6Ywkjyktsohkbp9bb45V6tEMoWhzFzXis+LrMehmJZZSys19Yxf1dopHx7WzIKxr5tK2dVcYmaCk2uqdjF4A==" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/autocomplete.js/0.38.0/autocomplete.jquery.min.js" integrity="sha512-GU9ayf+66Xx2TmpxqJpliWbT5PiGYxpaG8rfnBEk1LL8l1KGkRShhngwdXK1UgqhAzWpZHSiYPc09/NwDQIGyg==" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/mark.js/8.11.1/mark.min.js" integrity="sha512-5CYOlHXGh6QpOFA/TeTylKLWfB3ftPsde7AnmhuitiTX4K5SqCLBeKro6sPS8ilsz1Q4NRx3v8Ko2IBiszzdww==" crossorigin="anonymous"></script><!-- pkgdown --><script src="../pkgdown.js"></script><meta property="og:title" content="Convert between capture history data.frame formats. — capHistConvert"><meta property="og:description" content="Use to convert between simple versions of several capture history data.frame formats -- &amp;#8220;individual&amp;#8221;, &amp;#8220;frequency&amp;#8221;, &amp;#8220;event&amp;#8221;, &amp;#8220;MARK&amp;#8221;, and &amp;#8220;RMark&amp;#8221;. The primary use is to convert to the &amp;#8220;individual&amp;#8221; format for use in capHistSum."><meta property="og:image" content="https://fishr-core-team.github.io/FSA/logo.png"><!-- mathjax --><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js" integrity="sha256-nvJJv9wWKEm88qvoQl9ekL2J+k/RWIsaSScxxlsrv8k=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/config/TeX-AMS-MML_HTMLorMML.js" integrity="sha256-84DKXVJXs0/F8OTMzX4UR909+jtl4G7SPypPavF+GfA=" crossorigin="anonymous"></script><!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]--></head><body>
    <a href="#main" class="visually-hidden-focusable">Skip to contents</a>
    

    <nav class="navbar fixed-top navbar-dark navbar-expand-lg bg-primary"><div class="container">
    
    <a class="navbar-brand me-2" href="../index.html">FSA</a>

    <small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="Released version">0.9.5</small>

    
    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>

    <div id="navbar" class="collapse navbar-collapse ms-3">
      <ul class="navbar-nav me-auto"><li class="active nav-item">
  <a class="nav-link" href="../reference/index.html">Reference</a>
</li>
      </ul><form class="form-inline my-2 my-lg-0" role="search">
        <input type="search" class="form-control me-sm-2" aria-label="Toggle navigation" name="search-input" data-search-index="../search.json" id="search-input" placeholder="Search for" autocomplete="off"></form>

      <ul class="navbar-nav"><li class="nav-item">
  <a class="nav-link" href="../news/index.html">
    <span class="fa fa-newspaper"></span>
     
  </a>
</li>
<li class="nav-item">
  <a class="nav-link" href="../index.html">
    <span class="fa fa-home fa"></span>
     
  </a>
</li>
<li class="nav-item">
  <a class="external-link nav-link" href="https://github.com/fishR-Core-Team/FSA">
    <span class="fa fa-github fa"></span>
     
  </a>
</li>
      </ul></div>

    
  </div>
</nav><div class="container template-reference-topic">
<div class="row">
  <main id="main" class="col-md-9"><div class="page-header">
      <img src="../logo.png" class="logo" alt=""><h1>Convert between capture history data.frame formats.</h1>
      <small class="dont-index">Source: <a href="https://github.com/fishR-Core-Team/FSA/blob/HEAD/R/capHistConvert.R" class="external-link"><code>R/capHistConvert.R</code></a></small>
      <div class="d-none name"><code>capHistConvert.Rd</code></div>
    </div>

    <div class="ref-description section level2">
    <p>Use to convert between simple versions of several capture history data.frame formats -- “individual”, “frequency”, “event”, “MARK”, and “RMark”. The primary use is to convert to the “individual” format for use in <code><a href="capHistSum.html">capHistSum</a></code>.</p>
    </div>

    <div class="section level2">
    <h2 id="ref-usage">Usage<a class="anchor" aria-label="anchor" href="#ref-usage"></a></h2>
    <div class="sourceCode"><pre class="sourceCode r"><code><span><span class="fu">capHistConvert</span><span class="op">(</span></span>
<span>  <span class="va">df</span>,</span>
<span>  cols2use <span class="op">=</span> <span class="cn">NULL</span>,</span>
<span>  cols2ignore <span class="op">=</span> <span class="cn">NULL</span>,</span>
<span>  in.type <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span><span class="st">"frequency"</span>, <span class="st">"event"</span>, <span class="st">"individual"</span>, <span class="st">"MARK"</span>, <span class="st">"marked"</span>, <span class="st">"RMark"</span><span class="op">)</span>,</span>
<span>  out.type <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span><span class="st">"individual"</span>, <span class="st">"event"</span>, <span class="st">"frequency"</span>, <span class="st">"MARK"</span>, <span class="st">"marked"</span>, <span class="st">"RMark"</span><span class="op">)</span>,</span>
<span>  id <span class="op">=</span> <span class="cn">NULL</span>,</span>
<span>  event.ord <span class="op">=</span> <span class="cn">NULL</span>,</span>
<span>  freq <span class="op">=</span> <span class="cn">NULL</span>,</span>
<span>  var.lbls <span class="op">=</span> <span class="cn">NULL</span>,</span>
<span>  var.lbls.pre <span class="op">=</span> <span class="st">"event"</span>,</span>
<span>  include.id <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/ifelse.html" class="external-link">ifelse</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/NULL.html" class="external-link">is.null</a></span><span class="op">(</span><span class="va">id</span><span class="op">)</span>, <span class="cn">FALSE</span>, <span class="cn">TRUE</span><span class="op">)</span></span>
<span><span class="op">)</span></span></code></pre></div>
    </div>

    <div class="section level2">
    <h2 id="arguments">Arguments<a class="anchor" aria-label="anchor" href="#arguments"></a></h2>
    <dl><dt>df</dt>
<dd><p>A data.frame that contains the capture histories and, perhaps, a unique fish identifier or frequency variable. See details.</p></dd>


<dt>cols2use</dt>
<dd><p>A string or numeric vector that indicates columns in <code>df</code> to use. Negative numeric values will not use those columns. Cannot use both <code>cols2use</code> and <code>col2ignore</code>.</p></dd>


<dt>cols2ignore</dt>
<dd><p>A string or numeric vector that indicates columns in <code>df</code> to ignore. Typical columns to ignore are those that are not either in <code>id=</code> or <code>freq=</code> or part of the capture history data. Cannot use both <code>cols2use</code> and <code>col2ignore</code>.</p></dd>


<dt>in.type</dt>
<dd><p>A single string that indicates the type of capture history format to convert <b>FROM</b>.</p></dd>


<dt>out.type</dt>
<dd><p>A single string that indicates the type of capture history format to convert <b>TO</b>.</p></dd>


<dt>id</dt>
<dd><p>A string or numeric that indicates the column in <code>df</code> that contains the unique identifier for an individual fish. This argument is only used if <code>in.type="event"</code>, <code>in.type="individual"</code>, or, possibly, <code>in.type="RMark"</code>.</p></dd>


<dt>event.ord</dt>
<dd><p>A string that contains a vector of ordered levels to be used when <code>in.type="event"</code>. The default is to order alphabetically which may not be desirable if, for example, the events are labeled as ‘first’, ‘second’, ‘third’, and ‘fourth’. In this case, use <code>event.ord=c("first","second","third","fourth")</code>.</p></dd>


<dt>freq</dt>
<dd><p>A string or numeric that indicates the column in <code>df</code> that contains the frequency of individual fish corresponding to a capture history. This argument is only used if <code>in.type="MARK"</code>, <code>in.type="frequency"</code>, or, possibly, <code>in.type="RMark"</code>.</p></dd>


<dt>var.lbls</dt>
<dd><p>A string vector of labels for the columns that contain the returned individual or frequency capture histories. If <code>var.lbls=NULL</code> or the length is different then the number of events then default labels using <code>var.lbls.pre</code> will be used. This argument is only used if <code>out.type="frequency"</code> or <code>out.type="individual"</code>.</p></dd>


<dt>var.lbls.pre</dt>
<dd><p>A single string used as a prefix for the labels of the columns that contain the returned individual or frequency capture histories. This prefix will be appended with a number corresponding to the sample event. This argument is only used if <code>out.type="frequency"</code> or <code>out.type="individual"</code> and will be ignored if a proper vector is given in <code>var.lbls</code>.</p></dd>


<dt>include.id</dt>
<dd><p>A logical that indicates whether a unique fish identifier variable/column should be included in the output data.frame. This argument is only used if <code>out.type="individual"</code> or <code>out.type="RMark"</code>.</p></dd>

</dl></div>
    <div class="section level2">
    <h2 id="value">Value<a class="anchor" aria-label="anchor" href="#value"></a></h2>
    

<p>A data frame of the proper type given in <code>out.type</code> is returned. See details.</p>
    </div>
    <div class="section level2">
    <h2 id="details">Details<a class="anchor" aria-label="anchor" href="#details"></a></h2>
    <p><code><a href="capHistSum.html">capHistSum</a></code> requires capture histories to be recorded in the “individual” format. In this format, the data frame contains (at least) as many columns as sample events and as many rows as individually tagged fish. Optionally, the data.frame may also contain a column with unique fish identifiers (e.g., tag numbers). Each cell in the capture history portion of the data.frame contains a ‘0’ if the fish of that row was NOT seen in the event of that column and a ‘1’ if the fish of that row WAS seen in the event of that column. For example, suppose that five fish were marked on four sampling events; fish ‘17’ was captured on the first two events; fish ‘18’ was captured on the first and third events; fish ‘19’ was captured on only the third event; fish ‘20’ was captured on only the fourth event; and fish ‘21’ was captured on the first and second events. The “individual” capture history date.frame for these data looks like:</p>
<table class="table table"><tr><td>fish</td><td>event1</td><td>event2</td><td>event3</td><td>event4</td></tr><tr><td>17</td><td>1</td><td>1</td><td>0</td><td>0</td></tr><tr><td>18</td><td>1</td><td>0</td><td>1</td><td>0</td></tr><tr><td>19</td><td>0</td><td>0</td><td>1</td><td>0</td></tr><tr><td>20</td><td>0</td><td>0</td><td>0</td><td>1</td></tr><tr><td>21</td><td>1</td><td>1</td><td>0</td><td>0</td></tr></table><p>The “frequency” format data.frame (this format is used in <span class="pkg">Rcapture</span>) has unique capture histories in separate columns, as in the “individual” format, but also includes a column with the frequency of individuals that had the capture history of that row. It will not contain a fish identifier variable. The same data from above looks like:</p>
<table class="table table"><tr><td>event1</td><td>event2</td><td>event3</td><td>event4</td><td>freq</td></tr><tr><td>1</td><td>1</td><td>0</td><td>0</td><td>2</td></tr><tr><td>1</td><td>0</td><td>1</td><td>0</td><td>1</td></tr><tr><td>0</td><td>0</td><td>1</td><td>0</td><td>1</td></tr><tr><td>0</td><td>0</td><td>0</td><td>1</td><td>1</td></tr></table><p>The “event” format data.frame has a column with the unique fish identifier and a column with the event in which the fish of that row was observed. The same data from above looks like:</p>
<table class="table table"><tr><td>fish</td><td>event</td></tr><tr><td>17</td><td>1</td></tr><tr><td>18</td><td>1</td></tr><tr><td>21</td><td>1</td></tr><tr><td>17</td><td>2</td></tr><tr><td>21</td><td>2</td></tr><tr><td>18</td><td>3</td></tr><tr><td>19</td><td>3</td></tr><tr><td>20</td><td>4</td></tr></table><p>MARK (http://www.phidot.org/software/mark/index.html) is the “gold-standard” software for analyzing complex capture history information. In the “MARK” format the 0s and 1s of the capture histories are combined together as a string without any spaces. Thus, the “MARK” format has the capture history strings in one column with an additional column that contains the frequency of individuals that exhibited the capture history of that row. The final column ends with a semi-colon. The same data from above looks like:</p>
<table class="table table"><tr><td>ch</td><td>freq</td></tr><tr><td>0001</td><td>1;</td></tr><tr><td>0010</td><td>1;</td></tr><tr><td>1010</td><td>1;</td></tr><tr><td>1100</td><td>2;</td></tr></table><p>The <code>RMark</code> and <span class="pkg">marked</span> are packages used to replace some of the functionality of MARK or to interact with MARK. The “RMark” or “marked” format requires the capture histories as one string (must be a character string and called ‘ch’), as in the “MARK” format, but without the semicolon. The data.frame may be augmented with an identifier for individual fish OR with a frequency variable. If augmented with a unique fish identification variable then the same data from above looks like:</p>
<table class="table table"><tr><td>fish</td><td>ch</td></tr><tr><td>17</td><td>1100</td></tr><tr><td>18</td><td>1010</td></tr><tr><td>19</td><td>0010</td></tr><tr><td>20</td><td>0001</td></tr><tr><td>21</td><td>1100</td></tr></table><p>However, if augmented with a frequency variable then the same data from above looks like:</p>
<table class="table table"><tr><td>ch</td><td>freq</td></tr><tr><td>0001</td><td>1</td></tr><tr><td>0010</td><td>1</td></tr><tr><td>1010</td><td>1</td></tr><tr><td>1100</td><td>2</td></tr></table><p>Each of the formats can be used to convert from (i.e., in <code>in.type=</code>) or to convert to (i.e., in <code>out.type=</code>) with the exception that only the individual fish identifier version can be converted to when <code>out.type="RMark"</code>.</p>
    </div>
    <div class="section level2">
    <h2 id="note">Note<a class="anchor" aria-label="anchor" href="#note"></a></h2>
    <p>The formats as used here are simple in the sense that one is only allowed to have the individual fish identifier or the frequency variable in addition to the capture history information. More complex analyses may use a number of covariates. For these more complex analyses, one should work directly with the <span class="pkg">Rcapture</span>, <code>RMark</code>, or <span class="pkg">marked</span> packages.</p>
<p>This function also assumes that all unmarked captured fish are marked and returned to the population (i.e., no losses at the time of marking are allowed).</p>
    </div>
    <div class="section level2">
    <h2 id="warning">Warning<a class="anchor" aria-label="anchor" href="#warning"></a></h2>
    <p><code>capHistConvert</code> may give unwanted results if the data are <code>in.type="event"</code> but there are unused levels for the variable, as would result if the data.frame had been subsetted on the event variable. The unwanted results can be corrected by using <code>droplevels</code> before <code>capHistConvert</code>. See the last example for an example.</p>
    </div>
    <div class="section level2">
    <h2 id="ifar-chapter">IFAR Chapter<a class="anchor" aria-label="anchor" href="#ifar-chapter"></a></h2>
    <p>9-Abundance from Capture-Recapture Data.</p>
    </div>
    <div class="section level2">
    <h2 id="references">References<a class="anchor" aria-label="anchor" href="#references"></a></h2>
    <p>Ogle, D.H. 2016. <a href="https://fishr-core-team.github.io/fishR/pages/books.html#introductory-fisheries-analyses-with-r" class="external-link">Introductory Fisheries Analyses with R</a>. Chapman &amp; Hall/CRC, Boca Raton, FL.</p>
    </div>
    <div class="section level2">
    <h2 id="see-also">See also<a class="anchor" aria-label="anchor" href="#see-also"></a></h2>
    <div class="dont-index"><p>See <code><a href="capHistSum.html">capHistSum</a></code> to summarize “individual” capture histories into a format usable in <code><a href="mrClosed.html">mrClosed</a></code> and <code><a href="mrOpen.html">mrOpen</a></code>. Also see <span class="pkg">Rcapture</span>, <code>RMark</code>, or <span class="pkg">marked</span> packages for handling more complex analyses.</p></div>
    </div>
    <div class="section level2">
    <h2 id="author">Author<a class="anchor" aria-label="anchor" href="#author"></a></h2>
    <p>Derek H. Ogle, <a href="mailto:DerekOgle51@gmail.com">DerekOgle51@gmail.com</a></p>
    </div>

    <div class="section level2">
    <h2 id="ref-examples">Examples<a class="anchor" aria-label="anchor" href="#ref-examples"></a></h2>
    <div class="sourceCode"><pre class="sourceCode r"><code><span class="r-in"><span><span class="co">## A small example of 'event' format</span></span></span>
<span class="r-in"><span><span class="op">(</span> <span class="va">ex1</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/data.frame.html" class="external-link">data.frame</a></span><span class="op">(</span>fish<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span><span class="fl">17</span>,<span class="fl">18</span>,<span class="fl">21</span>,<span class="fl">17</span>,<span class="fl">21</span>,<span class="fl">18</span>,<span class="fl">19</span>,<span class="fl">20</span><span class="op">)</span>,yr<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span><span class="fl">1987</span>,<span class="fl">1987</span>,<span class="fl">1987</span>,<span class="fl">1988</span>,<span class="fl">1988</span>,<span class="fl">1989</span>,<span class="fl">1989</span>,<span class="fl">1990</span><span class="op">)</span><span class="op">)</span> <span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span>   fish   yr</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 1   17 1987</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 2   18 1987</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 3   21 1987</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 4   17 1988</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 5   21 1988</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 6   18 1989</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 7   19 1989</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 8   20 1990</span>
<span class="r-in"><span><span class="co"># convert to 'individual' format</span></span></span>
<span class="r-in"><span><span class="op">(</span> <span class="va">ex1.E2I</span> <span class="op">&lt;-</span> <span class="fu">capHistConvert</span><span class="op">(</span><span class="va">ex1</span>,id<span class="op">=</span><span class="st">"fish"</span>,in.type<span class="op">=</span><span class="st">"event"</span><span class="op">)</span> <span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span>   fish 1987 1988 1989 1990</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 1   17    1    1    0    0</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 2   18    1    0    1    0</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 3   19    0    0    1    0</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 4   20    0    0    0    1</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 5   21    1    1    0    0</span>
<span class="r-in"><span><span class="co"># convert to 'frequency' format</span></span></span>
<span class="r-in"><span><span class="op">(</span> <span class="va">ex1.E2F</span> <span class="op">&lt;-</span> <span class="fu">capHistConvert</span><span class="op">(</span><span class="va">ex1</span>,id<span class="op">=</span><span class="st">"fish"</span>,in.type<span class="op">=</span><span class="st">"event"</span>,out.type<span class="op">=</span><span class="st">"frequency"</span><span class="op">)</span> <span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span>   1987 1988 1989 1990 freq</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 1    0    0    0    1    1</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 2    0    0    1    0    1</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 3    1    0    1    0    1</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 4    1    1    0    0    2</span>
<span class="r-in"><span><span class="co"># convert to 'MARK' format</span></span></span>
<span class="r-in"><span><span class="op">(</span> <span class="va">ex1.E2M</span> <span class="op">&lt;-</span> <span class="fu">capHistConvert</span><span class="op">(</span><span class="va">ex1</span>,id<span class="op">=</span><span class="st">"fish"</span>,in.type<span class="op">=</span><span class="st">"event"</span>,out.type<span class="op">=</span><span class="st">"MARK"</span><span class="op">)</span> <span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span>     ch freq</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 1 0001   1;</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 2 0010   1;</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 3 1010   1;</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 4 1100   2;</span>
<span class="r-in"><span><span class="co"># convert to 'RMark' format</span></span></span>
<span class="r-in"><span><span class="op">(</span> <span class="va">ex1.E2R</span> <span class="op">&lt;-</span> <span class="fu">capHistConvert</span><span class="op">(</span><span class="va">ex1</span>,id<span class="op">=</span><span class="st">"fish"</span>,in.type<span class="op">=</span><span class="st">"event"</span>,out.type<span class="op">=</span><span class="st">"RMark"</span><span class="op">)</span> <span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span>   fish   ch</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 1   17 1100</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 2   18 1010</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 3   19 0010</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 4   20 0001</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 5   21 1100</span>
<span class="r-in"><span></span></span>
<span class="r-in"><span><span class="co">## convert converted 'individual' format ...</span></span></span>
<span class="r-in"><span><span class="co"># to 'frequency' format (must ignore "id")</span></span></span>
<span class="r-in"><span><span class="op">(</span> <span class="va">ex1.I2F</span> <span class="op">&lt;-</span> <span class="fu">capHistConvert</span><span class="op">(</span><span class="va">ex1.E2I</span>,id<span class="op">=</span><span class="st">"fish"</span>,in.type<span class="op">=</span><span class="st">"individual"</span>,out.type<span class="op">=</span><span class="st">"frequency"</span><span class="op">)</span> <span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span>   1987 1988 1989 1990 freq</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 1    0    0    0    1    1</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 2    0    0    1    0    1</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 3    1    0    1    0    1</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 4    1    1    0    0    2</span>
<span class="r-in"><span><span class="co"># to 'MARK' format</span></span></span>
<span class="r-in"><span><span class="op">(</span> <span class="va">ex1.I2M</span> <span class="op">&lt;-</span> <span class="fu">capHistConvert</span><span class="op">(</span><span class="va">ex1.E2I</span>,id<span class="op">=</span><span class="st">"fish"</span>,in.type<span class="op">=</span><span class="st">"individual"</span>,out.type<span class="op">=</span><span class="st">"MARK"</span><span class="op">)</span> <span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span>     ch freq</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 1 0001   1;</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 2 0010   1;</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 3 1010   1;</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 4 1100   2;</span>
<span class="r-in"><span><span class="co"># to 'RMark' format</span></span></span>
<span class="r-in"><span><span class="op">(</span> <span class="va">ex1.I2R</span> <span class="op">&lt;-</span> <span class="fu">capHistConvert</span><span class="op">(</span><span class="va">ex1.E2I</span>,id<span class="op">=</span><span class="st">"fish"</span>,in.type<span class="op">=</span><span class="st">"individual"</span>,out.type<span class="op">=</span><span class="st">"RMark"</span><span class="op">)</span> <span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span>   fish   ch</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 1   17 1100</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 2   18 1010</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 3   19 0010</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 4   20 0001</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 5   21 1100</span>
<span class="r-in"><span><span class="co"># to 'event' format</span></span></span>
<span class="r-in"><span><span class="op">(</span> <span class="va">ex1.I2E</span> <span class="op">&lt;-</span> <span class="fu">capHistConvert</span><span class="op">(</span><span class="va">ex1.E2I</span>,id<span class="op">=</span><span class="st">"fish"</span>,in.type<span class="op">=</span><span class="st">"individual"</span>,out.type<span class="op">=</span><span class="st">"event"</span><span class="op">)</span> <span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span>   fish event</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 1   17  1987</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 2   18  1987</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 3   21  1987</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 4   17  1988</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 5   21  1988</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 6   18  1989</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 7   19  1989</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 8   20  1990</span>
<span class="r-in"><span></span></span>
<span class="r-in"><span><span class="co">#' ## convert converted 'frequency' format ...</span></span></span>
<span class="r-in"><span><span class="co"># to 'individual' format</span></span></span>
<span class="r-in"><span><span class="op">(</span> <span class="va">ex1.F2I</span> <span class="op">&lt;-</span> <span class="fu">capHistConvert</span><span class="op">(</span><span class="va">ex1.E2F</span>,freq<span class="op">=</span><span class="st">"freq"</span>,in.type<span class="op">=</span><span class="st">"frequency"</span><span class="op">)</span> <span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span>   1987 1988 1989 1990</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 1    0    0    0    1</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 2    0    0    1    0</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 3    1    0    1    0</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 4    1    1    0    0</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 5    1    1    0    0</span>
<span class="r-in"><span><span class="op">(</span> <span class="va">ex1.F2Ia</span> <span class="op">&lt;-</span> <span class="fu">capHistConvert</span><span class="op">(</span><span class="va">ex1.E2F</span>,freq<span class="op">=</span><span class="st">"freq"</span>,in.type<span class="op">=</span><span class="st">"frequency"</span>,include.id<span class="op">=</span><span class="cn">TRUE</span><span class="op">)</span> <span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span>   id 1987 1988 1989 1990</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 1  1    0    0    0    1</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 2  2    0    0    1    0</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 3  3    1    0    1    0</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 4  4    1    1    0    0</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 5  5    1    1    0    0</span>
<span class="r-in"><span><span class="co"># to 'Mark' format</span></span></span>
<span class="r-in"><span><span class="op">(</span> <span class="va">ex1.F2M</span> <span class="op">&lt;-</span> <span class="fu">capHistConvert</span><span class="op">(</span><span class="va">ex1.E2F</span>,freq<span class="op">=</span><span class="st">"freq"</span>,in.type<span class="op">=</span><span class="st">"frequency"</span>,</span></span>
<span class="r-in"><span>                            out.type<span class="op">=</span><span class="st">"MARK"</span><span class="op">)</span> <span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span>     ch freq</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 1 0001   1;</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 2 0010   1;</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 3 1010   1;</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 4 1100   2;</span>
<span class="r-in"><span><span class="co"># to 'RMark' format</span></span></span>
<span class="r-in"><span><span class="op">(</span> <span class="va">ex1.F2R</span> <span class="op">&lt;-</span> <span class="fu">capHistConvert</span><span class="op">(</span><span class="va">ex1.E2F</span>,freq<span class="op">=</span><span class="st">"freq"</span>,in.type<span class="op">=</span><span class="st">"frequency"</span>,</span></span>
<span class="r-in"><span>                            out.type<span class="op">=</span><span class="st">"RMark"</span><span class="op">)</span> <span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span>     ch</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 1 0001</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 2 0010</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 3 1010</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 4 1100</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 5 1100</span>
<span class="r-in"><span><span class="op">(</span> <span class="va">ex1.F2Ra</span> <span class="op">&lt;-</span> <span class="fu">capHistConvert</span><span class="op">(</span><span class="va">ex1.E2F</span>,freq<span class="op">=</span><span class="st">"freq"</span>,in.type<span class="op">=</span><span class="st">"frequency"</span>,</span></span>
<span class="r-in"><span>                             out.type<span class="op">=</span><span class="st">"RMark"</span>,include.id<span class="op">=</span><span class="cn">TRUE</span><span class="op">)</span> <span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span>   id   ch</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 1  1 0001</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 2  2 0010</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 3  3 1010</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 4  4 1100</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 5  5 1100</span>
<span class="r-in"><span><span class="co"># to 'event' format</span></span></span>
<span class="r-in"><span><span class="op">(</span> <span class="va">ex1.F2E</span> <span class="op">&lt;-</span> <span class="fu">capHistConvert</span><span class="op">(</span><span class="va">ex1.E2F</span>,freq<span class="op">=</span><span class="st">"freq"</span>,in.type<span class="op">=</span><span class="st">"frequency"</span>,</span></span>
<span class="r-in"><span>                            out.type<span class="op">=</span><span class="st">"event"</span><span class="op">)</span> <span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span>   id event</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 1  3  1987</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 2  4  1987</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 3  5  1987</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 4  4  1988</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 5  5  1988</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 6  2  1989</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 7  3  1989</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 8  1  1990</span>
<span class="r-in"><span></span></span>
<span class="r-in"><span><span class="co">## convert converted 'MARK' format ...</span></span></span>
<span class="r-in"><span><span class="co"># to 'individual' format</span></span></span>
<span class="r-in"><span><span class="op">(</span> <span class="va">ex1.M2I</span> <span class="op">&lt;-</span> <span class="fu">capHistConvert</span><span class="op">(</span><span class="va">ex1.E2M</span>,freq<span class="op">=</span><span class="st">"freq"</span>,in.type<span class="op">=</span><span class="st">"MARK"</span><span class="op">)</span> <span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span>   event1 event2 event3 event4</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 1      0      0      0      1</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 2      0      0      1      0</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 3      1      0      1      0</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 4      1      1      0      0</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 5      1      1      0      0</span>
<span class="r-in"><span><span class="op">(</span> <span class="va">ex1.M2Ia</span> <span class="op">&lt;-</span> <span class="fu">capHistConvert</span><span class="op">(</span><span class="va">ex1.E2M</span>,freq<span class="op">=</span><span class="st">"freq"</span>,in.type<span class="op">=</span><span class="st">"MARK"</span>,include.id<span class="op">=</span><span class="cn">TRUE</span><span class="op">)</span> <span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span>   id event1 event2 event3 event4</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 1  1      0      0      0      1</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 2  2      0      0      1      0</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 3  3      1      0      1      0</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 4  4      1      1      0      0</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 5  5      1      1      0      0</span>
<span class="r-in"><span><span class="co"># to 'frequency' format</span></span></span>
<span class="r-in"><span><span class="op">(</span> <span class="va">ex1.M2F</span> <span class="op">&lt;-</span> <span class="fu">capHistConvert</span><span class="op">(</span><span class="va">ex1.E2M</span>,freq<span class="op">=</span><span class="st">"freq"</span>,in.type<span class="op">=</span><span class="st">"MARK"</span>,out.type<span class="op">=</span><span class="st">"frequency"</span><span class="op">)</span> <span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span>   event1 event2 event3 event4 freq</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 1      0      0      0      1    1</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 2      0      0      1      0    1</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 3      1      0      1      0    1</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 4      1      1      0      0    2</span>
<span class="r-in"><span><span class="co"># to 'RMark' format</span></span></span>
<span class="r-in"><span><span class="op">(</span> <span class="va">ex1.M2R</span> <span class="op">&lt;-</span> <span class="fu">capHistConvert</span><span class="op">(</span><span class="va">ex1.E2M</span>,freq<span class="op">=</span><span class="st">"freq"</span>,in.type<span class="op">=</span><span class="st">"MARK"</span>,out.type<span class="op">=</span><span class="st">"RMark"</span><span class="op">)</span> <span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span>     ch</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 1 0001</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 2 0010</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 3 1010</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 4 1100</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 5 1100</span>
<span class="r-in"><span><span class="op">(</span> <span class="va">ex1.M2Ra</span> <span class="op">&lt;-</span> <span class="fu">capHistConvert</span><span class="op">(</span><span class="va">ex1.E2M</span>,freq<span class="op">=</span><span class="st">"freq"</span>,in.type<span class="op">=</span><span class="st">"MARK"</span>,out.type<span class="op">=</span><span class="st">"RMark"</span>,include.id<span class="op">=</span><span class="cn">TRUE</span><span class="op">)</span> <span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span>   id   ch</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 1  1 0001</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 2  2 0010</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 3  3 1010</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 4  4 1100</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 5  5 1100</span>
<span class="r-in"><span><span class="co"># to 'event' format</span></span></span>
<span class="r-in"><span><span class="op">(</span> <span class="va">ex1.M2E</span> <span class="op">&lt;-</span> <span class="fu">capHistConvert</span><span class="op">(</span><span class="va">ex1.E2M</span>,freq<span class="op">=</span><span class="st">"freq"</span>,in.type<span class="op">=</span><span class="st">"MARK"</span>,out.type<span class="op">=</span><span class="st">"event"</span><span class="op">)</span> <span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span>   id  event</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 1  3 event1</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 2  4 event1</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 3  5 event1</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 4  4 event2</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 5  5 event2</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 6  2 event3</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 7  3 event3</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 8  1 event4</span>
<span class="r-in"><span> </span></span>
<span class="r-in"><span><span class="co">## convert converted 'RMark' format ...</span></span></span>
<span class="r-in"><span><span class="co"># to 'individual' format</span></span></span>
<span class="r-in"><span><span class="op">(</span> <span class="va">ex1.R2I</span> <span class="op">&lt;-</span> <span class="fu">capHistConvert</span><span class="op">(</span><span class="va">ex1.E2R</span>,id<span class="op">=</span><span class="st">"fish"</span>,in.type<span class="op">=</span><span class="st">"RMark"</span><span class="op">)</span> <span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span>   fish event1 event2 event3 event4</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 1   17      1      1      0      0</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 2   18      1      0      1      0</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 3   19      0      0      1      0</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 4   20      0      0      0      1</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 5   21      1      1      0      0</span>
<span class="r-in"><span><span class="co"># to 'frequency' format</span></span></span>
<span class="r-in"><span><span class="op">(</span> <span class="va">ex1.R2F</span> <span class="op">&lt;-</span> <span class="fu">capHistConvert</span><span class="op">(</span><span class="va">ex1.E2R</span>,id<span class="op">=</span><span class="st">"fish"</span>,in.type<span class="op">=</span><span class="st">"RMark"</span>,out.type<span class="op">=</span><span class="st">"frequency"</span><span class="op">)</span> <span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span>   event1 event2 event3 event4 freq</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 1      0      0      0      1    1</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 2      0      0      1      0    1</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 3      1      0      1      0    1</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 4      1      1      0      0    2</span>
<span class="r-in"><span><span class="co"># to 'MARK' format</span></span></span>
<span class="r-in"><span><span class="op">(</span> <span class="va">ex1.R2M</span> <span class="op">&lt;-</span> <span class="fu">capHistConvert</span><span class="op">(</span><span class="va">ex1.E2R</span>,id<span class="op">=</span><span class="st">"fish"</span>,in.type<span class="op">=</span><span class="st">"RMark"</span>,out.type<span class="op">=</span><span class="st">"MARK"</span><span class="op">)</span> <span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span>     ch freq</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 1 0001   1;</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 2 0010   1;</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 3 1010   1;</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 4 1100   2;</span>
<span class="r-in"><span><span class="co"># to 'event' format</span></span></span>
<span class="r-in"><span><span class="op">(</span> <span class="va">ex1.R2E</span> <span class="op">&lt;-</span> <span class="fu">capHistConvert</span><span class="op">(</span><span class="va">ex1.E2R</span>,id<span class="op">=</span><span class="st">"fish"</span>,in.type<span class="op">=</span><span class="st">"RMark"</span>,out.type<span class="op">=</span><span class="st">"event"</span><span class="op">)</span> <span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span>   fish  event</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 1   17 event1</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 2   18 event1</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 3   21 event1</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 4   17 event2</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 5   21 event2</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 6   18 event3</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 7   19 event3</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 8   20 event4</span>
<span class="r-in"><span></span></span>
<span class="r-in"><span><span class="co">## Remove semi-colon from MARK format to make a RMark 'frequency' format</span></span></span>
<span class="r-in"><span><span class="va">ex1.E2R1</span> <span class="op">&lt;-</span> <span class="va">ex1.E2M</span></span></span>
<span class="r-in"><span><span class="va">ex1.E2R1</span><span class="op">$</span><span class="va">freq</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/numeric.html" class="external-link">as.numeric</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/grep.html" class="external-link">sub</a></span><span class="op">(</span><span class="st">";"</span>,<span class="st">""</span>,<span class="va">ex1.E2R1</span><span class="op">$</span><span class="va">freq</span><span class="op">)</span><span class="op">)</span></span></span>
<span class="r-in"><span><span class="va">ex1.E2R1</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span>     ch freq</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 1 0001    1</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 2 0010    1</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 3 1010    1</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 4 1100    2</span>
<span class="r-in"><span><span class="co"># convert this to 'individual' format</span></span></span>
<span class="r-in"><span><span class="op">(</span> <span class="va">ex1.R2I1</span> <span class="op">&lt;-</span> <span class="fu">capHistConvert</span><span class="op">(</span><span class="va">ex1.E2R1</span>,freq<span class="op">=</span><span class="st">"freq"</span>,in.type<span class="op">=</span><span class="st">"RMark"</span><span class="op">)</span> <span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span>   event1 event2 event3 event4</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 1      0      0      0      1</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 2      0      0      1      0</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 3      1      0      1      0</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 4      1      1      0      0</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 5      1      1      0      0</span>
<span class="r-in"><span><span class="op">(</span> <span class="va">ex1.R2I1a</span> <span class="op">&lt;-</span> <span class="fu">capHistConvert</span><span class="op">(</span><span class="va">ex1.E2R1</span>,freq<span class="op">=</span><span class="st">"freq"</span>,in.type<span class="op">=</span><span class="st">"RMark"</span>,include.id<span class="op">=</span><span class="cn">TRUE</span><span class="op">)</span> <span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span>   id event1 event2 event3 event4</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 1  1      0      0      0      1</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 2  2      0      0      1      0</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 3  3      1      0      1      0</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 4  4      1      1      0      0</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 5  5      1      1      0      0</span>
<span class="r-in"><span><span class="co"># convert this to 'frequency' format</span></span></span>
<span class="r-in"><span><span class="op">(</span> <span class="va">ex1.R2F1</span> <span class="op">&lt;-</span> <span class="fu">capHistConvert</span><span class="op">(</span><span class="va">ex1.E2R1</span>,freq<span class="op">=</span><span class="st">"freq"</span>,in.type<span class="op">=</span><span class="st">"RMark"</span>,out.type<span class="op">=</span><span class="st">"frequency"</span><span class="op">)</span> <span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span>   event1 event2 event3 event4 freq</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 1      0      0      0      1    1</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 2      0      0      1      0    1</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 3      1      0      1      0    1</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 4      1      1      0      0    2</span>
<span class="r-in"><span><span class="co"># convert this to 'MARK' format</span></span></span>
<span class="r-in"><span><span class="op">(</span> <span class="va">ex1.R2M1</span> <span class="op">&lt;-</span> <span class="fu">capHistConvert</span><span class="op">(</span><span class="va">ex1.E2R1</span>,freq<span class="op">=</span><span class="st">"freq"</span>,in.type<span class="op">=</span><span class="st">"RMark"</span>,out.type<span class="op">=</span><span class="st">"MARK"</span><span class="op">)</span> <span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span>     ch freq</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 1 0001   1;</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 2 0010   1;</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 3 1010   1;</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 4 1100   2;</span>
<span class="r-in"><span><span class="co"># convert this to 'event' format</span></span></span>
<span class="r-in"><span><span class="op">(</span> <span class="va">ex1.R2E1</span> <span class="op">&lt;-</span> <span class="fu">capHistConvert</span><span class="op">(</span><span class="va">ex1.E2R1</span>,freq<span class="op">=</span><span class="st">"freq"</span>,in.type<span class="op">=</span><span class="st">"RMark"</span>,out.type<span class="op">=</span><span class="st">"event"</span><span class="op">)</span> <span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span>   id  event</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 1  3 event1</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 2  4 event1</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 3  5 event1</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 4  4 event2</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 5  5 event2</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 6  2 event3</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 7  3 event3</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 8  1 event4</span>
<span class="r-in"><span></span></span>
<span class="r-in"><span></span></span>
<span class="r-in"><span><span class="co">########################################################################</span></span></span>
<span class="r-in"><span><span class="co">## A small example using character ids</span></span></span>
<span class="r-in"><span><span class="op">(</span> <span class="va">ex2</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/data.frame.html" class="external-link">data.frame</a></span><span class="op">(</span>fish<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span><span class="st">"id17"</span>,<span class="st">"id18"</span>,<span class="st">"id21"</span>,<span class="st">"id17"</span>,<span class="st">"id21"</span>,<span class="st">"id18"</span>,<span class="st">"id19"</span>,<span class="st">"id20"</span><span class="op">)</span>,</span></span>
<span class="r-in"><span>                    yr<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span><span class="fl">1987</span>,<span class="fl">1987</span>,<span class="fl">1987</span>,<span class="fl">1988</span>,<span class="fl">1988</span>,<span class="fl">1989</span>,<span class="fl">1989</span>,<span class="fl">1990</span><span class="op">)</span><span class="op">)</span> <span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span>   fish   yr</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 1 id17 1987</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 2 id18 1987</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 3 id21 1987</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 4 id17 1988</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 5 id21 1988</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 6 id18 1989</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 7 id19 1989</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 8 id20 1990</span>
<span class="r-in"><span><span class="co"># convert to 'individual' format</span></span></span>
<span class="r-in"><span><span class="op">(</span> <span class="va">ex2.E2I</span> <span class="op">&lt;-</span> <span class="fu">capHistConvert</span><span class="op">(</span><span class="va">ex2</span>,id<span class="op">=</span><span class="st">"fish"</span>,in.type<span class="op">=</span><span class="st">"event"</span><span class="op">)</span> <span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span>   fish 1987 1988 1989 1990</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 1 id17    1    1    0    0</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 2 id18    1    0    1    0</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 3 id19    0    0    1    0</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 4 id20    0    0    0    1</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 5 id21    1    1    0    0</span>
<span class="r-in"><span><span class="co"># convert to 'frequency' format</span></span></span>
<span class="r-in"><span><span class="op">(</span> <span class="va">ex2.E2F</span> <span class="op">&lt;-</span> <span class="fu">capHistConvert</span><span class="op">(</span><span class="va">ex2</span>,id<span class="op">=</span><span class="st">"fish"</span>,in.type<span class="op">=</span><span class="st">"event"</span>,out.type<span class="op">=</span><span class="st">"frequency"</span><span class="op">)</span> <span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span>   1987 1988 1989 1990 freq</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 1    0    0    0    1    1</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 2    0    0    1    0    1</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 3    1    0    1    0    1</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 4    1    1    0    0    2</span>
<span class="r-in"><span><span class="co"># convert to 'MARK' format</span></span></span>
<span class="r-in"><span><span class="op">(</span> <span class="va">ex2.E2M</span> <span class="op">&lt;-</span> <span class="fu">capHistConvert</span><span class="op">(</span><span class="va">ex2</span>,id<span class="op">=</span><span class="st">"fish"</span>,in.type<span class="op">=</span><span class="st">"event"</span>,out.type<span class="op">=</span><span class="st">"MARK"</span><span class="op">)</span> <span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span>     ch freq</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 1 0001   1;</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 2 0010   1;</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 3 1010   1;</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 4 1100   2;</span>
<span class="r-in"><span><span class="co"># convert to 'RMark' format</span></span></span>
<span class="r-in"><span><span class="op">(</span> <span class="va">ex2.E2R</span> <span class="op">&lt;-</span> <span class="fu">capHistConvert</span><span class="op">(</span><span class="va">ex2</span>,id<span class="op">=</span><span class="st">"fish"</span>,in.type<span class="op">=</span><span class="st">"event"</span>,out.type<span class="op">=</span><span class="st">"RMark"</span><span class="op">)</span> <span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span>   fish   ch</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 1 id17 1100</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 2 id18 1010</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 3 id19 0010</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 4 id20 0001</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 5 id21 1100</span>
<span class="r-in"><span></span></span>
<span class="r-in"><span><span class="co">## convert converted 'individual' format ...</span></span></span>
<span class="r-in"><span><span class="co"># to 'frequency' format</span></span></span>
<span class="r-in"><span><span class="op">(</span> <span class="va">ex2.I2F</span> <span class="op">&lt;-</span> <span class="fu">capHistConvert</span><span class="op">(</span><span class="va">ex2.E2I</span>,id<span class="op">=</span><span class="st">"fish"</span>,in.type<span class="op">=</span><span class="st">"individual"</span>,out.type<span class="op">=</span><span class="st">"frequency"</span><span class="op">)</span> <span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span>   1987 1988 1989 1990 freq</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 1    0    0    0    1    1</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 2    0    0    1    0    1</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 3    1    0    1    0    1</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 4    1    1    0    0    2</span>
<span class="r-in"><span><span class="co"># to 'MARK' format</span></span></span>
<span class="r-in"><span><span class="op">(</span> <span class="va">ex2.I2M</span> <span class="op">&lt;-</span> <span class="fu">capHistConvert</span><span class="op">(</span><span class="va">ex2.E2I</span>,id<span class="op">=</span><span class="st">"fish"</span>,in.type<span class="op">=</span><span class="st">"individual"</span>,out.type<span class="op">=</span><span class="st">"MARK"</span><span class="op">)</span> <span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span>     ch freq</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 1 0001   1;</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 2 0010   1;</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 3 1010   1;</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 4 1100   2;</span>
<span class="r-in"><span><span class="co"># to 'RMark' format</span></span></span>
<span class="r-in"><span><span class="op">(</span> <span class="va">ex2.I2R</span> <span class="op">&lt;-</span> <span class="fu">capHistConvert</span><span class="op">(</span><span class="va">ex2.E2I</span>,id<span class="op">=</span><span class="st">"fish"</span>,in.type<span class="op">=</span><span class="st">"individual"</span>,out.type<span class="op">=</span><span class="st">"RMark"</span><span class="op">)</span> <span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span>   fish   ch</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 1 id17 1100</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 2 id18 1010</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 3 id19 0010</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 4 id20 0001</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 5 id21 1100</span>
<span class="r-in"><span><span class="co"># to 'event' format</span></span></span>
<span class="r-in"><span><span class="op">(</span> <span class="va">ex2.I2E</span> <span class="op">&lt;-</span> <span class="fu">capHistConvert</span><span class="op">(</span><span class="va">ex2.E2I</span>,id<span class="op">=</span><span class="st">"fish"</span>,in.type<span class="op">=</span><span class="st">"individual"</span>,out.type<span class="op">=</span><span class="st">"event"</span><span class="op">)</span> <span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span>   fish event</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 1 id17  1987</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 2 id18  1987</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 3 id21  1987</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 4 id17  1988</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 5 id21  1988</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 6 id18  1989</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 7 id19  1989</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 8 id20  1990</span>
<span class="r-in"><span></span></span>
<span class="r-in"><span><span class="co">## demo use of var.lbls</span></span></span>
<span class="r-in"><span><span class="op">(</span> <span class="va">ex2.E2Ia</span> <span class="op">&lt;-</span> <span class="fu">capHistConvert</span><span class="op">(</span><span class="va">ex2</span>,id<span class="op">=</span><span class="st">"fish"</span>,in.type<span class="op">=</span><span class="st">"event"</span>,var.lbls.pre<span class="op">=</span><span class="st">"Sample"</span><span class="op">)</span> <span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span>   fish 1987 1988 1989 1990</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 1 id17    1    1    0    0</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 2 id18    1    0    1    0</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 3 id19    0    0    1    0</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 4 id20    0    0    0    1</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 5 id21    1    1    0    0</span>
<span class="r-in"><span><span class="op">(</span> <span class="va">ex2.E2Ib</span> <span class="op">&lt;-</span> <span class="fu">capHistConvert</span><span class="op">(</span><span class="va">ex2</span>,id<span class="op">=</span><span class="st">"fish"</span>,in.type<span class="op">=</span><span class="st">"event"</span>,</span></span>
<span class="r-in"><span>              var.lbls<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span><span class="st">"first"</span>,<span class="st">"second"</span>,<span class="st">"third"</span>,<span class="st">"fourth"</span><span class="op">)</span><span class="op">)</span> <span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span>   fish first second third fourth</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 1 id17     1      1     0      0</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 2 id18     1      0     1      0</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 3 id19     0      0     1      0</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 4 id20     0      0     0      1</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 5 id21     1      1     0      0</span>
<span class="r-in"><span></span></span>
<span class="r-in"><span><span class="co">## demo use of event.ord</span></span></span>
<span class="r-in"><span><span class="op">(</span> <span class="va">ex2.I2Ea</span> <span class="op">&lt;-</span> <span class="fu">capHistConvert</span><span class="op">(</span><span class="va">ex2.E2Ib</span>,id<span class="op">=</span><span class="st">"fish"</span>,in.type<span class="op">=</span><span class="st">"individual"</span>,out.type<span class="op">=</span><span class="st">"event"</span><span class="op">)</span> <span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span>   fish  event</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 1 id17  first</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 2 id18  first</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 3 id21  first</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 4 id17 second</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 5 id21 second</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 6 id18  third</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 7 id19  third</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 8 id20 fourth</span>
<span class="r-in"><span><span class="op">(</span> <span class="va">ex2.E2Ibad</span> <span class="op">&lt;-</span> <span class="fu">capHistConvert</span><span class="op">(</span><span class="va">ex2.I2Ea</span>,id<span class="op">=</span><span class="st">"fish"</span>,in.type<span class="op">=</span><span class="st">"event"</span><span class="op">)</span> <span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span>   fish first fourth second third</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 1 id17     1      0      1     0</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 2 id18     1      0      0     1</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 3 id19     0      0      0     1</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 4 id20     0      1      0     0</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 5 id21     1      0      1     0</span>
<span class="r-in"><span><span class="op">(</span> <span class="va">ex2.E2Igood</span> <span class="op">&lt;-</span> <span class="fu">capHistConvert</span><span class="op">(</span><span class="va">ex2.I2Ea</span>,id<span class="op">=</span><span class="st">"fish"</span>,in.type<span class="op">=</span><span class="st">"event"</span>,</span></span>
<span class="r-in"><span>                 event.ord<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span><span class="st">"first"</span>,<span class="st">"second"</span>,<span class="st">"third"</span>,<span class="st">"fourth"</span><span class="op">)</span><span class="op">)</span> <span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span>   fish first second third fourth</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 1 id17     1      1     0      0</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 2 id18     1      0     1      0</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 3 id19     0      0     1      0</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 4 id20     0      0     0      1</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 5 id21     1      1     0      0</span>
<span class="r-in"><span></span></span>
<span class="r-in"><span><span class="co">## ONLY RUN IN INTERACTIVE MODE</span></span></span>
<span class="r-in"><span><span class="kw">if</span> <span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/interactive.html" class="external-link">interactive</a></span><span class="op">(</span><span class="op">)</span><span class="op">)</span> <span class="op">{</span></span></span>
<span class="r-in"><span></span></span>
<span class="r-in"><span><span class="co">########################################################################</span></span></span>
<span class="r-in"><span><span class="co">## A larger example of 'frequency' format (data from Rcapture package)</span></span></span>
<span class="r-in"><span><span class="fu"><a href="https://rdrr.io/r/utils/data.html" class="external-link">data</a></span><span class="op">(</span><span class="va">bunting</span>,package<span class="op">=</span><span class="st">"Rcapture"</span><span class="op">)</span></span></span>
<span class="r-in"><span><span class="fu"><a href="https://rdrr.io/r/utils/head.html" class="external-link">head</a></span><span class="op">(</span><span class="va">bunting</span><span class="op">)</span></span></span>
<span class="r-in"><span><span class="co"># convert to 'individual' format</span></span></span>
<span class="r-in"><span><span class="va">bun.F2I</span> <span class="op">&lt;-</span> <span class="fu">capHistConvert</span><span class="op">(</span><span class="va">bunting</span>,in.type<span class="op">=</span><span class="st">"frequency"</span>,freq<span class="op">=</span><span class="st">"freq"</span><span class="op">)</span></span></span>
<span class="r-in"><span><span class="fu"><a href="https://rdrr.io/r/utils/head.html" class="external-link">head</a></span><span class="op">(</span><span class="va">bun.F2I</span><span class="op">)</span></span></span>
<span class="r-in"><span><span class="co"># convert to 'MARK' format</span></span></span>
<span class="r-in"><span><span class="va">bun.F2M</span> <span class="op">&lt;-</span> <span class="fu">capHistConvert</span><span class="op">(</span><span class="va">bunting</span>,id<span class="op">=</span><span class="st">"id"</span>,in.type<span class="op">=</span><span class="st">"frequency"</span>,freq<span class="op">=</span><span class="st">"freq"</span>,out.type<span class="op">=</span><span class="st">"MARK"</span><span class="op">)</span></span></span>
<span class="r-in"><span><span class="fu"><a href="https://rdrr.io/r/utils/head.html" class="external-link">head</a></span><span class="op">(</span><span class="va">bun.F2M</span><span class="op">)</span></span></span>
<span class="r-in"><span><span class="co"># convert converted 'individual' back to 'MARK' format</span></span></span>
<span class="r-in"><span><span class="va">bun.I2M</span> <span class="op">&lt;-</span> <span class="fu">capHistConvert</span><span class="op">(</span><span class="va">bun.F2I</span>,id<span class="op">=</span><span class="st">"id"</span>,in.type<span class="op">=</span><span class="st">"individual"</span>,out.type<span class="op">=</span><span class="st">"MARK"</span><span class="op">)</span></span></span>
<span class="r-in"><span><span class="fu"><a href="https://rdrr.io/r/utils/head.html" class="external-link">head</a></span><span class="op">(</span><span class="va">bun.I2M</span><span class="op">)</span></span></span>
<span class="r-in"><span><span class="co"># convert converted 'individual' back to 'frequency' format</span></span></span>
<span class="r-in"><span><span class="va">bun.I2F</span> <span class="op">&lt;-</span> <span class="fu">capHistConvert</span><span class="op">(</span><span class="va">bun.F2I</span>,id<span class="op">=</span><span class="st">"id"</span>,in.type<span class="op">=</span><span class="st">"individual"</span>,</span></span>
<span class="r-in"><span>           out.type<span class="op">=</span><span class="st">"frequency"</span>,var.lbls.pre<span class="op">=</span><span class="st">"Sample"</span><span class="op">)</span></span></span>
<span class="r-in"><span><span class="fu"><a href="https://rdrr.io/r/utils/head.html" class="external-link">head</a></span><span class="op">(</span><span class="va">bun.I2F</span><span class="op">)</span></span></span>
<span class="r-in"><span></span></span>
<span class="r-in"><span></span></span>
<span class="r-in"><span><span class="co">########################################################################</span></span></span>
<span class="r-in"><span><span class="co">## A larger example of 'marked' or 'RMark' format, but with a covariate</span></span></span>
<span class="r-in"><span><span class="co">##   and when the covariate is removed there is no frequency or individual</span></span></span>
<span class="r-in"><span><span class="co">##   fish identifier.</span></span></span>
<span class="r-in"><span><span class="fu"><a href="https://rdrr.io/r/utils/data.html" class="external-link">data</a></span><span class="op">(</span><span class="va">dipper</span>,package<span class="op">=</span><span class="st">"marked"</span><span class="op">)</span></span></span>
<span class="r-in"><span><span class="fu"><a href="https://rdrr.io/r/utils/head.html" class="external-link">head</a></span><span class="op">(</span><span class="va">dipper</span><span class="op">)</span></span></span>
<span class="r-in"><span><span class="co"># isolate males and females</span></span></span>
<span class="r-in"><span><span class="va">dipperF</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/subset.html" class="external-link">subset</a></span><span class="op">(</span><span class="va">dipper</span>,<span class="va">sex</span><span class="op">==</span><span class="st">"Female"</span><span class="op">)</span></span></span>
<span class="r-in"><span><span class="va">dipperM</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/subset.html" class="external-link">subset</a></span><span class="op">(</span><span class="va">dipper</span>,<span class="va">sex</span><span class="op">==</span><span class="st">"Male"</span><span class="op">)</span></span></span>
<span class="r-in"><span><span class="co"># convert females to 'individual' format</span></span></span>
<span class="r-in"><span><span class="va">dipF.R2I</span> <span class="op">&lt;-</span> <span class="fu">capHistConvert</span><span class="op">(</span><span class="va">dipperF</span>,cols2ignore<span class="op">=</span><span class="st">"sex"</span>,in.type<span class="op">=</span><span class="st">"RMark"</span><span class="op">)</span></span></span>
<span class="r-in"><span><span class="fu"><a href="https://rdrr.io/r/utils/head.html" class="external-link">head</a></span><span class="op">(</span><span class="va">dipF.R2I</span><span class="op">)</span></span></span>
<span class="r-in"><span><span class="co"># convert males to 'individual' format</span></span></span>
<span class="r-in"><span><span class="va">dipM.R2I</span> <span class="op">&lt;-</span> <span class="fu">capHistConvert</span><span class="op">(</span><span class="va">dipperM</span>,cols2ignore<span class="op">=</span><span class="st">"sex"</span>,in.type<span class="op">=</span><span class="st">"RMark"</span><span class="op">)</span></span></span>
<span class="r-in"><span><span class="fu"><a href="https://rdrr.io/r/utils/head.html" class="external-link">head</a></span><span class="op">(</span><span class="va">dipM.R2I</span><span class="op">)</span></span></span>
<span class="r-in"><span><span class="co"># add sex variable to each data.frame and then combine</span></span></span>
<span class="r-in"><span><span class="va">dipF.R2I</span><span class="op">$</span><span class="va">sex</span> <span class="op">&lt;-</span> <span class="st">"Female"</span></span></span>
<span class="r-in"><span><span class="va">dipM.R2I</span><span class="op">$</span><span class="va">sex</span> <span class="op">&lt;-</span> <span class="st">"Male"</span></span></span>
<span class="r-in"><span><span class="va">dip.R2I</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/cbind.html" class="external-link">rbind</a></span><span class="op">(</span><span class="va">dipF.R2I</span>,<span class="va">dipM.R2I</span><span class="op">)</span></span></span>
<span class="r-in"><span><span class="fu"><a href="https://rdrr.io/r/utils/head.html" class="external-link">head</a></span><span class="op">(</span><span class="va">dip.R2I</span><span class="op">)</span></span></span>
<span class="r-in"><span><span class="fu"><a href="https://rdrr.io/r/utils/head.html" class="external-link">tail</a></span><span class="op">(</span><span class="va">dip.R2I</span><span class="op">)</span></span></span>
<span class="r-in"><span></span></span>
<span class="r-in"><span><span class="op">}</span> <span class="co"># end interactive</span></span></span>
<span class="r-in"><span></span></span>
<span class="r-in"><span></span></span>
<span class="r-in"><span><span class="co">## An example of problem with unused levels</span></span></span>
<span class="r-in"><span><span class="co">## Create a set of test data with several groups</span></span></span>
<span class="r-in"><span><span class="op">(</span> <span class="va">df</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/data.frame.html" class="external-link">data.frame</a></span><span class="op">(</span>fish<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span><span class="st">"id17"</span>,<span class="st">"id18"</span>,<span class="st">"id21"</span>,<span class="st">"id17"</span>,<span class="st">"id21"</span>,<span class="st">"id18"</span>,<span class="st">"id19"</span>,<span class="st">"id20"</span>,<span class="st">"id17"</span><span class="op">)</span>,</span></span>
<span class="r-in"><span>                   group<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span><span class="st">"B1"</span>,<span class="st">"B1"</span>,<span class="st">"B1"</span>,<span class="st">"B2"</span>,<span class="st">"B2"</span>,<span class="st">"B3"</span>,<span class="st">"B4"</span>,<span class="st">"C1"</span>,<span class="st">"C1"</span><span class="op">)</span><span class="op">)</span> <span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span>   fish group</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 1 id17    B1</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 2 id18    B1</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 3 id21    B1</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 4 id17    B2</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 5 id21    B2</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 6 id18    B3</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 7 id19    B4</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 8 id20    C1</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 9 id17    C1</span>
<span class="r-in"><span><span class="co">#  Let's assume the user wants to subset the data from the "B" group</span></span></span>
<span class="r-in"><span><span class="op">(</span> <span class="va">df1</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/subset.html" class="external-link">subset</a></span><span class="op">(</span><span class="va">df</span>,<span class="va">group</span> <span class="op"><a href="https://rdrr.io/r/base/match.html" class="external-link">%in%</a></span> <span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span><span class="st">"B1"</span>,<span class="st">"B2"</span>,<span class="st">"B3"</span>,<span class="st">"B4"</span><span class="op">)</span><span class="op">)</span> <span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span>   fish group</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 1 id17    B1</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 2 id18    B1</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 3 id21    B1</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 4 id17    B2</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 5 id21    B2</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 6 id18    B3</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 7 id19    B4</span>
<span class="r-in"><span><span class="co">#  Looks like capHistConvert() is still using the unused factor</span></span></span>
<span class="r-in"><span><span class="co">#  level from group C</span></span></span>
<span class="r-in"><span><span class="fu">capHistConvert</span><span class="op">(</span><span class="va">df1</span>,id<span class="op">=</span><span class="st">"fish"</span>,in.type<span class="op">=</span><span class="st">"event"</span><span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span>   fish B1 B2 B3 B4</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 1 id17  1  1  0  0</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 2 id18  1  0  1  0</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 3 id19  0  0  0  1</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 4 id21  1  1  0  0</span>
<span class="r-in"><span><span class="co"># use droplevels() to remove the unused groups and no problem</span></span></span>
<span class="r-in"><span><span class="va">df1</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/droplevels.html" class="external-link">droplevels</a></span><span class="op">(</span><span class="va">df1</span><span class="op">)</span></span></span>
<span class="r-in"><span><span class="fu">capHistConvert</span><span class="op">(</span><span class="va">df1</span>,id<span class="op">=</span><span class="st">"fish"</span>,in.type<span class="op">=</span><span class="st">"event"</span><span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span>   fish B1 B2 B3 B4</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 1 id17  1  1  0  0</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 2 id18  1  0  1  0</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 3 id19  0  0  0  1</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 4 id21  1  1  0  0</span>
<span class="r-in"><span></span></span>
</code></pre></div>
    </div>
  </main><aside class="col-md-3"><nav id="toc"><h2>On this page</h2>
    </nav></aside></div>


    <footer><div class="pkgdown-footer-left">
  <p></p><p>Developed by <a href="http://derekogle.com" class="external-link">Derek H. Ogle</a>, Jason C. Doll, A. Powell Wheeler, Alexis Dinno.</p>
</div>

<div class="pkgdown-footer-right">
  <p></p><p>Site built with <a href="https://pkgdown.r-lib.org/" class="external-link">pkgdown</a> 2.0.7.</p>
</div>

    </footer></div>

  

  

  </body></html>

