Dear colleagues, particularly academic ones, So I'm creating a Microsoft Word template for myself so that every time I teach a new course, I don't have to enter in the dates manually for each class session. I'd like to use an R script that can generate an irregular series of dates starting from one date (semester begin) to another (semester end) using an irregular interval in between (Tuesdays and Thursdays, for example). I know that a regular series of dates is no problem, but what about an irregular series? Yours, Simon Kisss ********************************* Simon J. Kiss, PhD SSHRC and DAAD Post-Doctoral Fellow John F. Kennedy Institute of North America Studies Free University of Berlin Lansstra?e 7-9 14195 Berlin, Germany Cell: +49 (0)1525-300-2812, Web: http://www.jfki.fu-berlin.de/index.html
Previously in R 2.9.2 I used the following to convert from an improperly formatted NA string into one that is a bit more consistent. gsub("N\A", "NA", "N\A", fixed=TRUE) This worked in R 2.9.2, but now in R 2.11.1 it doesn't seem to work an throws the following error. Error: '\A' is an unrecognized escape in character string starting "N\A" I guess my questions are the following: (1) Is this expected behavior? (2) If it is expected behavior, what is the proper way to replace "N\A" with "NA" and "N\\A" with "NA"? Thank you again for all the help and insight.
A fairly simple way is to generate one series with all the Tuesdays, then another with all the Thursdays, combine and sort.> sort( c( seq.Date( as.Date('2010-6-29'), by='week', length.out=10),+ seq.Date( as.Date('2010-7-1'), by='week', length.out=10) ) + ) [1] "2010-06-29" "2010-07-01" "2010-07-06" "2010-07-08" "2010-07-13" [6] "2010-07-15" "2010-07-20" "2010-07-22" "2010-07-27" "2010-07-29" [11] "2010-08-03" "2010-08-05" "2010-08-10" "2010-08-12" "2010-08-17" [16] "2010-08-19" "2010-08-24" "2010-08-26" "2010-08-31" "2010-09-02">-- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.snow at imail.org 801.408.8111> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of Simon Kiss > Sent: Tuesday, June 29, 2010 4:22 AM > To: r-help at r-project.org > Subject: [R] generate irregular series of dates > > Dear colleagues, particularly academic ones, > So I'm creating a Microsoft Word template for myself so that every > time I teach a new course, I don't have to enter in the dates manually > for each class session. > I'd like to use an R script that can generate an irregular series of > dates starting from one date (semester begin) to another (semester > end) using an irregular interval in between (Tuesdays and Thursdays, > for example). > I know that a regular series of dates is no problem, but what about an > irregular series? > Yours, > Simon Kisss > ********************************* > Simon J. Kiss, PhD > SSHRC and DAAD Post-Doctoral Fellow > John F. Kennedy Institute of North America Studies > Free University of Berlin > Lansstra?e 7-9 > 14195 Berlin, Germany > Cell: +49 (0)1525-300-2812, > Web: http://www.jfki.fu-berlin.de/index.html > > ______________________________________________ > 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.
On Tue, Jun 29, 2010 at 6:22 AM, Simon Kiss <sjkiss at gmail.com> wrote:> Dear colleagues, particularly academic ones, > So I'm creating a Microsoft Word template for myself so that every time I > teach a new course, I don't have to enter in the dates manually for each > class session. > I'd like to use an R script that can generate an irregular series of dates > starting from one date (semester begin) to another (semester end) using an > irregular interval in between (Tuesdays and Thursdays, for example). > I know that a regular series of dates is no problem, but what about an > irregular series?Generate all the dates in the range of interest and then pick off the Tuesdays and Thursdays: dd <- seq(as.Date("2010-01-01"), as.Date("2010-12-31"), "day") dd[weekdays(dd) %in% c("Tuesday", "Thursday")]
Seemingly Similar Threads
- Problem with recode -Error in parse(text = range[[1]][1]) : unexpected end of input in " c(0"
- help calculating variable based on factor level of another
- Grouping and stacking bar plot for categorical variables
- Stacked Histogram, multiple lines for dates of news stories?
- Finding different hues for a mosaic plot compatible with grayscale printing