Quantcast

subsetting a dataset

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

subsetting a dataset

bdossman
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


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: subsetting a dataset

Rui Barradas
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.
>
> ______________________________________________
> [hidden email] 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.
>

______________________________________________
[hidden email] 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.
Loading...