Slaapkamer
Slaapkamer

Reputation: 75

R as.yearqtr from zoo package: how to remove the blank

I'm using the function as.yearqtr() from the zoo package to convert a date like this:

2012-01-01

...and I would like to have it like this:

2012Q1

The problem with as.yearqtr is that it create a blank space between the year and the 'Q':

2012 Q1

How can I remove this blank?

Thanks!

Upvotes: 2

Views: 480

Answers (1)

akrun
akrun

Reputation: 887048

We can change with format. It would no longer have the class yearqtr, but would be just character

library(zoo)
format(as.yearqtr('2012-01-01'), '%YQ%q')
#[1] "2012Q1"

Or with regex

sub(" ", "", as.yearqtr('2012-01-01'))

Upvotes: 1

Related Questions