[R] subset

David Winsemius dwinsemius at comcast.net
Thu Jun 23 20:46:22 CEST 2011


On Jun 23, 2011, at 1:47 PM, yf wrote:

> Dear all,
>
> How can I do the subset fucntion from the table?

What table?

> I want to do the subset for
> the less than 50.
> I tried b8a<-subset(b8, (table(g$book)<50)==TRUE) but it didn't work.

And you neither shown us what these structures are nor posted an error  
message.

> Thanks.
>
> table(g$ book )
>

The subset function is for dataframes. Tables are essentially  
matrices. Use logical indexing with "[".


> 119 121 134 160 161 170 175 179 190 193 225 226 256 260
> 130  89  50  87    74  23  85    47  93  64  16    69  48   38

The top row are names and the bottom row are values

Perhaps (but how b8 enters into this remains unclear) :

tbl <- table(g$ book )

tbl[ tbl < 50]

>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/subset-tp3620557p3620557.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list