From m@ech|er @end|ng |rom @t@t@m@th@ethz@ch  Tue Oct 10 18:18:22 2023
From: m@ech|er @end|ng |rom @t@t@m@th@ethz@ch (Martin Maechler)
Date: Tue, 10 Oct 2023 18:18:22 +0200
Subject: [Rd] Subset has No Examples for Vector Data
In-Reply-To: <f18c5f6b-93d1-4fa9-b1b8-23c6123aa436@sapo.pt>
References: <SY2PR01MB300337984DDDA5045487BBEDCDCDA@SY2PR01MB3003.ausprd01.prod.outlook.com>
 <f18c5f6b-93d1-4fa9-b1b8-23c6123aa436@sapo.pt>
Message-ID: <25893.31054.576410.309672@stat.math.ethz.ch>

>>>>> Rui Barradas 
>>>>>     on Tue, 10 Oct 2023 12:17:19 +0100 writes:

    > ?s 11:00 de 10/10/2023, Dario Strbenac via R-devel escreveu:
    >> Hello,
    >> 
    >> Could the documentation page for subset gain an example of how to use it for something other than a data frame or matrix? I arrived at
    >> 
    >>> random <- LETTERS[rpois(100, 10)]
    >>> subset(table(random), x > 10)
    >> named integer(0)
    >> 
    >> I expected a part of the table to be returned rather than an empty vector.
    >> 
    >> --------------------------------------
    >> Dario Strbenac
    >> University of Sydney
    >> Camperdown NSW 2050
    >> Australia

    > If you want to subset then you must refer to a variable in the original 
    > data set. In your example there is no 'x' in the output of table.


    > set.seed(2023)
    > random <- LETTERS[rpois(100, 10)]
    > (tbl <- table(random))
    > #> random
    > #>  C  D  E  F  G  H  I  J  K  L  M  N  P  Q  S
    > #>  1  2  4  4  8 13 14 10 17  9 11  2  1  3  1

    > subset(tbl, tbl > 10)
    > #> random
    > #>  H  I  K  M
    > #> 13 14 17 11


    > So it is subsetting vector data as wanted.
    > It is your expectation that a part of the table should be returned that 
    > is not in agreement with the data you have.

    > Hope this helps,

    > Rui Barradas

Thank you, Rui, for helping!

yes, *help*ing
      <---> 
that (original post) was very much for R-help,  not at all for R-devel ...

Martin



[Rd] Subset has No Examples for Vector Data
Martin Maechler