Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Character joining and deleting in R

I have a data and it has a column yearmonthweek. For example, 2012y05m1wk means 1st week of May, 2012. Likewise, 2012y11m3wk means 3rd week of November, 2012.
data looks like this:

data<-data.frame(yearmonthweek=c("2012y05m1wk","2012y05m2wk","2012y05m4wk","2012y11m3wk"))

Here, I want to change the expression as below:

data<-data.frame(yearmonthweek=c("2012051","2012052","2012054","2012113"))

How can I do?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Remove the letters from the column could work:

gsub('[a-z]','',data$yearmonthweek)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading