[R] Alter character attribute

2010-10-28 Thread LCOG1
Hi everyone I have some records that include a date attribute for the date and time but i need to separate the data and analyze it separately in GIS by Month and Year, so i need to pull these attributes out and create their own attribute field. So the input: RawData2.. returns ID

Re: [R] Alter character attribute

2010-10-28 Thread jim holtman
try this: x - read.table(textConnection( ID date time + 1 22 9/10/2007 0:00:00 + 2 44 2/2/2006 0:00:00), header = TRUE) closeAllConnections() x ID datetime 1 22 9/10/2007 0:00:00 2 44 2/2/2006 0:00:00 x$month - sub(^([[:digit:]]+).*, \\1, x$date) x$year -

Re: [R] Alter character attribute

2010-10-28 Thread jim holtman
I didn't see you test so, so here is the solution with your data: RawData2..-data.frame(ID=c(22,44),period_end_date=c(9/10/2007 0:00:00, + 2/2/2006 0:00:00)) RawData2..$month - sub(^([[:digit:]]+).*, \\1, RawData2..$period_end_date) RawData2..$year - sub(.*/([[:digit:]]+) .*, \\1,

Re: [R] Alter character attribute

2010-10-28 Thread Phil Spector
If you convert the dates to R date objects, I think things will be easier: rawdata2$period_end_date = as.Date(rawdata2$period_end_date,format='%m/%d/%Y') rawdata2$mon = as.numeric(format(rawdata2$period_end_date,'%m')) rawdata2$year = as.numeric(format(rawdata2$period_end_date,'%Y')) (I'm

Re: [R] Alter character attribute

2010-10-28 Thread LCOG1
Changing the filed into date format then pulling out the month/year worked best. Thanks, i knew it was gonna be easy. Cheers -- View this message in context: http://r.789695.n4.nabble.com/Alter-character-attribute-tp3018202p3018255.html Sent from the R help mailing list archive at Nabble.com.