R - what does this tapply() function do? : <p>Please excuse my terrible knowledge of the language - just started looking at it a few hours ago.</p>

<p>I'm trying to understand this code and what it produces but quite unsure. Given that the value of <code>inclusions</code> is 10, why is the output what it is?</p>

<p><code>seps &lt;- tapply(diff, nonCore, function(x) sort(x)[inclusions])</code></p>

<p>Outputs</p>

<pre><code>"","x"
"ab",23
"ad",15
</code></pre>

<p>The value of <code>diff</code> is</p>

<pre><code>"","x"
"1",31
"2",43
"3",37
"4",22
"5",27
"6",13
"7",24
"8",7
"9",26
"10",29
"11",2
"12",15
"13",10
"14",38
"15",23
"16",21
"17",46
"18",10
"19",20
"20",46
"21",20
"22",32
"23",26
"24",11
"25",16
"26",2
"27",13
"28",4
"29",15
"30",18
"31",13
"32",26
"33",1
"34",27
"35",12
"36",10
"37",35
"38",21
"39",9
"40",35
</code></pre>

<p>The value of <code>nonCore</code> is</p>

<pre><code>"","x"
"1","ab"
"2","ab"
"3","ab"
"4","ab"
"5","ab"
"6","ab"
"7","ab"
"8","ab"
"9","ab"
"10","ab"
"11","ab"
"12","ab"
"13","ab"
"14","ab"
"15","ab"
"16","ab"
"17","ab"
"18","ab"
"19","ab"
"20","ab"
"21","ad"
"22","ad"
"23","ad"
"24","ad"
"25","ad"
"26","ad"
"27","ad"
"28","ad"
"29","ad"
"30","ad"
"31","ad"
"32","ad"
"33","ad"
"34","ad"
"35","ad"
"36","ad"
"37","ad"
"38","ad"
"39","ad"
"40","ad"
</code></pre>
