[R] subsetting a dataset

Rui Barradas ruipbarradas at sapo.pt
Sun Jun 24 14:51:11 CEST 2012


Hello,

Try the following.

ix <- with(dataset, TAG.ID %in% 12:20 | TAG.ID %in% 192:212)
dataset[ix, ]

or

ix <- with(dataset, (12 <= TAG.ID & TAG.ID <=20) | (192 <= TAG.ID & 
TAG.ID <= 212))

if the variable is not integer.

Also, read the manual, this, index vectors, is there. (R-intro.pdf).

Hope this helps,

Rui Barradas

Em 24-06-2012 13:31, bdossman escreveu:
> Hi
>
> I am a beginner R user and need a little help with the subset function.
>
> I have a dataset with  columns; TOWER,TAG.ID, DATETIME (POSIXct class) and I
> would like to subset my data by specific TAG.ID (e.g TAG.IDs 12:20 and
> 192:212). Is there an easy way to preform this operation?
>
> Thanks
> Bryant
>
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/subsetting-a-dataset-tp4634326.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.
>



More information about the R-help mailing list