[R] Formatting YYYY-MM after reading text file [RESOLVED]

David Winsemius dwinsemius at comcast.net
Sat Jun 27 01:51:41 CEST 2015


On Jun 26, 2015, at 3:02 PM, Rich Shepard wrote:

> On Fri, 26 Jun 2015, MacQueen, Don wrote:
> 
>> I would have just assigned them all to the first day of the month, using
>> as.Date( paste0(allchem$sampdate,'-01') )
>> (or maybe the middle of the month represented by the 15th)
>> and then had a variable that was of the Date class in the base R (with
>> which I am familiar, no small consideration).
> 
> Don,
> 
>  The original data had the day of the month, but that's not important. I
> suppose I could leave it in and still analyze and plot by month.

I suppose I'm jumping into the middle of a conversation but I'd say it's going to be safe to leave as a Date and then use `format(dt.val , "%Y-%m")` or similar for grouping and axis labels.

My 2 cents.

> 
>> Depending on what needs to be done with them -- plotting with a date axis?
>> -- calculating elapsed time between sampling events? -- I suppose one or
>> the other of 'yearmon' or 'Date' might be more convenient.
> 
>  Simple is better.

Much as I appreciate the value of the yearmon-class, it's not as full featured as class-Date.

-- 

David Winsemius
Alameda, CA, USA



More information about the R-help mailing list