nogias nogias - 11 months ago 72
R Question

R - what does this tapply() function do?

Please excuse my terrible knowledge of the language - just started looking at it a few hours ago.

I'm trying to understand this code and what it produces but quite unsure. Given that the value of

is 10, why is the output what it is?

seps <- tapply(diff, nonCore, function(x) sort(x)[inclusions])



The value of


The value of


Answer Source

You should supply the code to construct the vectors diff and nonCore, as it is those who could help you need to do massive edits...

That said, what is happening is that your sorting the combination of the vectors according to ab and and ad. ab matches against the first 20 in diff and ad the last 20. Then you just subset the list that is created with the element number that is given by inclusion.

It's the same as running the function without [inclusion] and doing this afterwards: