[R] month and output

David Winsemius dwinsemius at comcast.net
Sat May 7 07:18:05 CEST 2016


> On May 6, 2016, at 5:15 PM, Ashta <sewashm at 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") )

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 <dwinsemius at comcast.net> wrote:
>> 
>>> On May 6, 2016, at 4:30 PM, David Winsemius <dwinsemius at comcast.net> wrote:
>>> 
>>> 
>>>> On May 6, 2016, at 4:11 PM, Ashta <sewashm at 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 at 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



More information about the R-help mailing list