You could install and load the 'lubridate' package, which has month() and month<-() functions so you can do the following:
> z <- as.Date(c("2015-01-29", "2016-01-29", "2016-05-07", "2016-12-25")) > z [1] "2015-01-29" "2016-01-29" "2016-05-07" "2016-12-25" > month(z) <- month(z) + 1 > z [1] NA "2016-02-29" "2016-06-07" "2017-01-25" Bill Dunlap TIBCO Software wdunlap tibco.com On Fri, May 6, 2016 at 5:15 PM, Ashta <sewa...@gmail.com> wrote: > Thank you very much David. > > So there is no general formal that works year all round. > > The first one work only Jan to Nov > today <- Sys.Date() > nextmo<- paste0( month.abb[ as.numeric(format(today, format="%m"))+1] , > format(today,"%Y") ) > [1] "Jun2016" > > The second one works only for the last month of the year. > today <- as.Date("2008-12-01") > nextmo<- paste0(m <- month.abb[(as.numeric(format(today, > format="%m"))+1) %/% 12] , > as.numeric( format(today,"%Y") ) + (m == "Jan") ) > nextmo > > > Many thanks > > > > > > On Fri, May 6, 2016 at 6:40 PM, David Winsemius <dwinsem...@comcast.net> > wrote: > > > >> On May 6, 2016, at 4:30 PM, David Winsemius <dwinsem...@comcast.net> > wrote: > >> > >> > >>> On May 6, 2016, at 4:11 PM, Ashta <sewa...@gmail.com> wrote: > >>> > >>> Hi all, > >>> > >>> I am trying to ge get the next month of the year. > >>> > >>> today <- Sys.Date() > >>> xx<- format(today, format="%B%Y") > >>> > >>> I got "May2016", but I want Jun2016. How do I do that? > >> > >> today <- Sys.Date() > >> nextmo<- paste0( month.abb[ as.numeric(format(today, format="%m"))+1] , > >> format(today,"%Y") ) > >> [1] "Jun2016" > > > > It occurred to me that at the end of the year you would want to > increment the year as well. This calculates the next month and increments > the year value if needed: > > > > today <- as.Date("2008-12-01") > > nextmo<- paste0(m <- month.abb[(as.numeric(format(today, > format="%m"))+1) %/% 12] , > > as.numeric( format(today,"%Y") ) + (m == "Jan") ) > > nextmo > > #[1] "Jan2009" > >> > >>> > >>> My other question is that, I read a data and do some analysis and I > >>> want to send all the results of the analysis to a pdf file > >>> > >>> Example > >>> x5 <- runif(15, 5.0, 7.5) > >>> x5 > >>> > >>> > >>> I tried this one > >>> > >>> pdf(file=" test.pdf") > >>> x5 > >>> dev.off() > >> > >> pdf() opens a graphics device, so you need a function that establishes > a coordinate system: > >> > >> x5 <- runif(15, 5.0, 7.5) > >> pdf(file=" test.pdf"); > >> plot(1,1,type="n") > >> text(1, 1, paste(round(x5, 2), collapse="\n") ) > >> dev.off() > >> > > > > If you need to suppress the axes and their labels: > > > > pdf(file=" test.pdf"); plot(1,1, type="n", axes=FALSE, xlab="", ylab="") > > text(1, 1, paste(round(x5, 2), collapse="\n") ) > > dev.off() > > > >> I doubt that this is what you really want, and suspect you really need > to be studying the capabilities supported by the knitr package. If I'm > wrong about that and you want a system that supports drawing and text on a > blank page, then first study: > >> > >>> library(grid) > >>> help(pac=grid) > >> > >> If you choose that route then the text "R Graphics" by Paul Murrell > will be indispensable. > >> > >> -- > >> David Winsemius > >> Alameda, CA, USA > >> > >> ______________________________________________ > >> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > >> 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. > > > > David Winsemius > > Alameda, CA, USA > > > > ______________________________________________ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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. > [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.