[R] Subset of a subset?

R. Michael Weylandt michael.weylandt at gmail.com
Tue Nov 15 00:48:22 CET 2011


You haven't really said much about your overall project, but if you
are subsetting by time, it seems like you might want to use the xts
time series class. It implements ISO8601 for quick subsetting, which
seems perfect for what you are doing.

Here's a made up example:

X = xts(cumsum(rnorm(1e4)), Sys.time() + cumsum(runif(1e4)*100))

length(X)
length(X["T09:13:00/T13:40:00"])

That, for example, finds all data poitns between 9:13 am and 1:40pm on any day.

You can pull out days even easier:

length(X['2011-11-13::2011-11-15'])

Hope this helps,

Michael

On Mon, Nov 14, 2011 at 4:41 PM, jck13 <jennakeane at hotmail.com> wrote:
> Hi All-
>
> I have created a subset of my original csv for the times I am interested in
> (9, 12, 3). I have a subset for all of those times then each individually. I
> would like to have specific case studies to analyze individually for those
> times. For example, I want to look at 2009/06/01-2009/06/10. Is the easiest
> way to created a subset of ss? I haven't been able to figure out the easiest
> way since I created by subsets based on the hour.
>
> Thanks for any help!!
>
> da=paste(Date)
> tiso= strptime(da,format="%d/%m/%Y %H:%M")
> tiso$h
> df1= data.frame(tiso, mv)
>
> ## creating a subset of 9am, 12pm and 3pm.
>
> ss= subset(mv, tiso$h==9| tiso$h ==12| tiso$h==15)
> ss9= subset(mv, tiso$h==9)
> ss12= subset(mv, tiso$h==12)
> ss15= subset (mv, tiso$h==15)
>
> ##create a subset of each event
>
> ss0609= subset( ss, tiso==2009-06-01 | tiso==2009-06-02)
>
> Example of Data:
> Date    T002_03 T002_25 T004_03 T004_25 T006_03
> 31/03/2007 23:00        31      3       18      5       6       5.8     7       3.5
> 1/4/2007 0:00   30      2       16      5       7       2.5     8       4.7
> 1/4/2007 1:00   34      1       15      4       7       2.7     12      4.4
> 1/4/2007 2:00   34      0       11      6       6       2.5     16      4.4
> 1/4/2007 3:00   37      0       NoData  6       6       2.7     NoData
> 1/4/2007 4:00   34      1       13      4       5       1.4     12      4
> 1/4/2007 5:00   23      1       15      2       4       1.4     12      4.5
> 1/4/2007 6:00   13      1       16      3       3       2.2     14      4.1
> 1/4/2007 7:00   30      0       10      5       5       2.3     15      4.8
> 1/4/2007 8:00   36      0       18      4       13      5.3     22      2.7
> 1/4/2007 9:00   38      0       23      4       23      2.8     31      1.1
>
>
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Subset-of-a-subset-tp4040973p4040973.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