Reputation: 53
I am new to R and i am not able to find how to do this.
Consider a table named Trial like this
Col1 Col2 Col3
1 hey June 24, 2013 5:15:06 PM GMT+05:30
2 hello april 20, 2013 5:15:06 PM GMT+05:30
3 hey July 23, 2012 5:15:06 PM GMT+05:30
How do i replace values of Col3 in Trial to
Col1 Col2 Col3
1 hey June 2013
2 hello april 2013
3 hey July 2012
ie.i need to extract only month and year and make a new column or replace in the same. Thnx in advance!
Upvotes: 3
Views: 600
Reputation: 121568
Use this for example:
dat$Col3 <- gsub('(^\\w+).*, ([0-9]{4}).*','\\1 \\2',dat$Col3)
Upvotes: 1