Re: [R] month and output
Thank you David! On Sat, May 7, 2016 at 12:18 AM, David Winsemius wrote: > >> On May 6, 2016, at 5:15 PM, Ashta 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") ) > > Sorry; > > This works as intended: > >> today <- seq( from=as.Date("2008-1-01"), length=13, by="1 mo" ) >> >> nextmo<- paste0( m <- month.abb[ as.numeric(format(today, format="%m")) %% >> 12+1] , > +as.numeric( format(today,"%Y") ) + (m=="Jan") ); nextmo > [1] "Feb2008" "Mar2008" "Apr2008" "May2008" "Jun2008" "Jul2008" "Aug2008" > "Sep2008" > [9] "Oct2008" "Nov2008" "Dec2008" "Jan2009" "Feb2009" > > > >> nextmo >> >> >> Many thanks >> >> >> >> >> >> On Fri, May 6, 2016 at 6:40 PM, David Winsemius >> wrote: >>> On May 6, 2016, at 4:30 PM, David Winsemius wrote: > On May 6, 2016, at 4:11 PM, Ashta 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 >>> > > 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.
Re: [R] month and output
> On May 6, 2016, at 5:15 PM, Ashta 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") ) Sorry; This works as intended: > today <- seq( from=as.Date("2008-1-01"), length=13, by="1 mo" ) > > nextmo<- paste0( m <- month.abb[ as.numeric(format(today, format="%m")) %% > 12+1] , +as.numeric( format(today,"%Y") ) + (m=="Jan") ); nextmo [1] "Feb2008" "Mar2008" "Apr2008" "May2008" "Jun2008" "Jul2008" "Aug2008" "Sep2008" [9] "Oct2008" "Nov2008" "Dec2008" "Jan2009" "Feb2009" > nextmo > > > Many thanks > > > > > > On Fri, May 6, 2016 at 6:40 PM, David Winsemius > wrote: >> >>> On May 6, 2016, at 4:30 PM, David Winsemius wrote: >>> >>> On May 6, 2016, at 4:11 PM, Ashta 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 >> 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.
Re: [R] month and output
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 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 > wrote: > > > >> On May 6, 2016, at 4:30 PM, David Winsemius > wrote: > >> > >> > >>> On May 6, 2016, at 4:11 PM, Ashta 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.
Re: [R] month and output
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 wrote: > >> On May 6, 2016, at 4:30 PM, David Winsemius wrote: >> >> >>> On May 6, 2016, at 4:11 PM, Ashta 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.
Re: [R] month and output
To add to what David said, maybe you want ?sink or ?capture.output . If you're really looking to combine your own text and R output, than knitr is probably what you want. The RStudio ide integrates this stuff, so you may want to look at that, too. Cheers, Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Fri, May 6, 2016 at 4:11 PM, Ashta 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? > > 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() > > I found the file is empty. I would appreciate if you help me out. > > Thanks in advance > > __ > 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. __ 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.
Re: [R] month and output
> On May 6, 2016, at 4:30 PM, David Winsemius wrote: > > >> On May 6, 2016, at 4:11 PM, Ashta 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.
Re: [R] month and output
> On May 6, 2016, at 4:11 PM, Ashta 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" > > 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() 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.