Last answered:

29 Sept 2022

Posted on:

28 Sept 2022

0

Resolved: Year names as numeric

Hello, just want to clarify something.

It's been two lectures now that we name the columns with years, in this case defined in dimnames = ..., c("2014", "2015", "2016))).

Since a year is numeric/integer in nature, can we define a vector of double/integer type, such as c(2014, 2015, 2016), then set it as a row/column name? We already verified from a previous quiz that we can set integers as vector names of a string vector.

Thanks,
Carl

2 answers ( 1 marked as helpful)
Instructor
Posted on:

29 Sept 2022

0

Hi Carl,
thanks for reaching out!
You can use a numerical vector for your dates, as years can be seen as a numerical value.
However, what I can suggest here is actually looking at years as dates, as this is the actual format we need. Working with time series data is always tricky and requires a bit of preparation. In this case for R, it's a bit involved having only years as dates, as the format usually requires the full date, i.e. 2022-09-08.
What you can try to avoid the issue is use the lubridate library and try the following code:the following:

library(lubridate)
yrs <- c(2001, 2002, 2002, 2002, 2003, 2005)
yr <- as.Date(as.character(yrs), format = "%Y")
y <- year(yr)

Let me know if you have any further questions on the topic.

Best,
365 Eli

Posted on:

29 Sept 2022

0

I see, that's an interesting information. I'll keep that in mind.
Thanks Eli.

Submit an answer