2

Here is the description of these two operators from the doc An Introduction to R:

M_1 : M_2
The tensor product of M_1 and M_2. If both terms are factors, then the “subclasses” factor.

M_1 %in% M_2
Similar to M_1:M_2, but with a different coding.

This does not actually tell the difference between the two. My questions are,

  1. What's the difference between M_1 : M_2 and M_1 %in% M_2 as formula notations, or under what circumstances do we have to use the former or the latter?
  2. What does with a different coding mean in this context?
gdf
  • 21
  • 2
  • 1
    `:` means to,`%in%` means `in` and will return a boolean. See for instance `1:4` and `1 %in% 4`. 1 to 4 here would form a numeric vector of 1 to 4 while `%in%` just tests if something is in a given vector – NelsonGon May 21 '20 at 15:46
  • 1
    @NelsonGon that is not true in the formula context, which the part of the docs OP is referencing. – Brian May 21 '20 at 17:43
  • That's right. It seems the question was edited or I missed it when I commented. Sorry! @Brian. – NelsonGon May 22 '20 at 18:05
  • Since this was edited, my earlier comment is erroneous. See this instead: https://stackoverflow.com/questions/40567421/asterisk-vs-colon-in-r-formulas `%in%` here means nesting instead too. – NelsonGon May 22 '20 at 18:32

0 Answers0