Skip to content

Simple and fast date format conversion

2 messages · Zanella Marco, Brian G. Peterson

#
Gentleman,
I have to convert a date to this format: nov 2009

A) I've loaded a daily dataset of returns like this:
Date Ret
1 20090729  3.08

B) Naturally, I've transformed Date with as.Date() and now I have:
Date Ret
1 2009-07-29 3.08

Ok, now I want to analyse data also accorpated for months, and weeks, not only daily.
I think the ways to do this can be various:
1) In A), where Date is simply a number, truncate the last two digits of Date (es. 200907). Then I can subset data for month thanks to new Date's format.
2) In B), after Date conversion to date format, proceed with a new format conversion (es. lug 2009)

But, how I can do this with R? I tried with truncate() and strptime() but failed.

Thanks.

Marco

____________________________________________________________
GET FREE 5GB EMAIL - Check out spam free email with many cool features!
Visit http://www.inbox.com/email to find out more!
#
Zanella Marco wrote:
You're working with returns, so you need to aggregate your returns.  You 
can't treat them like prices and simply grab the last price in your 
observation period.

Do you have a price (value) series available?  If not, convert it to a 
wealth index first.

With either price data or a wealth index, you can use to.period in xts 
to convert.  If you need returns for your analysis, the wealth index is 
fungible back to returns.

Further clarification would benefit from a sample data series.

Regards,

    - Brian