סינון לפי חודש ספציפי

23 views
Skip to first unread message

Itzik

unread,
Aug 24, 2017, 5:13:45 AM8/24/17
to Israel R User Group
שלום,


יש לי קובץ (CSV) שנראה כך:

time  txx  normalised
1950-01 19.3 -1.58621
1950-02 21.7 -1.19524
1950-03 24 -0.82057
1950-04 32.6 0.580387
1950-05 32.5 0.564096
1950-06 31.6 0.417485
1950-07 31.5 0.401194
1950-08 32.9 0.629257
1950-09 31.8 0.450065
1950-10 29.7 0.107971
1950-11 27.7 -0.21783
1950-12 23.7 -0.86944
1951-01 21 -1.30928
1951-02 21.2 -1.2767
1951-03 26.5 -0.41332

כיצד ניתן ליצור סדרת זמן עבור חודש ספציפי בלבד? למשל, ברצוני לקבל סדרת זמן של חודש ינואר בלבד לתקופה 2016-1950 (ואחר כך לעשות את כל המניפולציות הסטטיסטיות עבור אותו החודש בתקופה הנתונה).

תודה,
איציק

Michael Dorman

unread,
Aug 24, 2017, 7:07:42 AM8/24/17
to Israel R User Group
אפשר ליצור עמודה חדשה של "חודש" ואז לסנן לפיה, למשל כך

> dat$month = substr(dat$time, 6, 7)
> head(dat)
     time  txx normalised month
1 1950-01 19.3  -1.586210    01
2 1950-02 21.7  -1.195240    02
3 1950-03 24.0  -0.820570    03
4 1950-04 32.6   0.580387    04
5 1950-05 32.5   0.564096    05
6 1950-06 31.6   0.417485    06
> dat = dat[dat$month == "01", ]
> head(dat)
      time  txx normalised month
1  1950-01 19.3   -1.58621    01
13 1951-01 21.0   -1.30928    01

Michael Dorman

unread,
Aug 24, 2017, 7:08:00 AM8/24/17
to Israel R User Group
> dat$month = substr(dat$time, 6, 7)
> head(dat)
     time  txx normalised month
1 1950-01 19.3  -1.586210    01
2 1950-02 21.7  -1.195240    02
3 1950-03 24.0  -0.820570    03
4 1950-04 32.6   0.580387    04
5 1950-05 32.5   0.564096    05
6 1950-06 31.6   0.417485    06
> dat = dat[dat$month == "01", ]
> head(dat)
      time  txx normalised month
1  1950-01 19.3   -1.58621    01
13 1951-01 21.0   -1.30928    01

amit gal

unread,
Aug 24, 2017, 7:29:02 AM8/24/17
to israel-r-...@googlegroups.com
באופן כללי הייתי ממליץ להשתמש בפונקציות שעושות פארסינג לאובייקטים שמייצגים זמן. במקרה שלך עושה רושם שהפקודה as.yearmon של חבילה zoo תעזור מאד, ואני תמיד ממליץ על חבילת lubridate לעבודה עם תאריכים ומניפולציות שלהם. שתי החבילות האלה יחד יאפשרו לך לעשות המון דברים עם בניה ותחזוקה וניתוח של סדרות עתיות.
לסינון פשוט במקרה שלך:

month(as.yearon(dat$time))

נותן את החודש בשנה.

בחבילה zoo יש גם פקודות ייעודיות כדי לחלץ מתוך סדרה גדולה, תתי סדרות, חלונות, אגרגציות תקופתיות עם או בלי חפיפה וכו'. שמאפשרות לעבור בקלות לצירי זמן שונים.


--
You received this message because you are subscribed to the Google Groups "Israel R User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to israel-r-user-group+unsub...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Itzik

unread,
Aug 24, 2017, 8:58:21 AM8/24/17
to Israel R User Group
מעולה, תודה רבה,
איציק

בתאריך יום חמישי, 24 באוגוסט 2017 בשעה 14:29:02 UTC+3, מאת Amit Gal:
Reply all
Reply to author
Forward
0 new messages