[R] How to combine character month and year columns into one column

2014-09-23 Thread Kuma Raj
Dear R users, I have a data with month and year columns which are both characters and wanted to create a new column like Jan-1999 with the following code. The result is all NA for the month part. What is wrong with the and what is the right way to combine the two? ddf$MonthDay -

Re: [R] How to combine character month and year columns into one column

2014-09-23 Thread Marc Schwartz
On Sep 23, 2014, at 10:41 AM, Kuma Raj pollar...@gmail.com wrote: Dear R users, I have a data with month and year columns which are both characters and wanted to create a new column like Jan-1999 with the following code. The result is all NA for the month part. What is wrong with the and

Re: [R] How to combine character month and year columns into one column

2014-09-23 Thread Kuma Raj
Many thanks for your quick answer which has created what I wished. May I ask followup question on the same issue. I failed to convert the new column into date format with this code. The class of MonthDay is still character df$MonthDay - format(df$MonthDay, format=c(%b %Y)) I would appreciate if

Re: [R] How to combine character month and year columns into one column

2014-09-23 Thread Marc Schwartz
Two things: 1. You need to convert the result of the paste() to a Date related class. 2. R's standard Date classes require a full date, so you would have to add in some default day of the month: See ?as.Date NewDate - as.Date(paste(month.abb[as.numeric(ddf$month)], 01, ddf$Year, sep=-),

Re: [R] How to combine character month and year columns into one column

2014-09-23 Thread David Winsemius
Marc; Feature request: Would it make sense to construct month.abb as a named vector so that the operation that was attempted would have succeeded? Adding alphanumeric names c(01, 02, 03, 04, 05, 06, 07, 08, 09, 10, 11, 12) would allow character extraction from substring or regex extracted

Re: [R] How to combine character month and year columns into one column

2014-09-23 Thread Marc Schwartz
Hi David, My initial reaction (not that the decision is mine to make), is that from a technical perspective, obviously indexing by name is common. There are two considerations, off the top of my head: 1. There would be a difference, of course, between: month.abb[1] NA NA and