replace NA by date

I have a tibble that when convert to date is set na to one of the rows and I want to change it and replace the true date to it.

tb <- tibble::tribble(
          ~dateissue,
           13990508L,
           13990507L,
           13990506L,
           13990505L,
           13990504L,
           13990501L,
           13990431L,
           13990430L,
           13990429L,
           13990428L,
           13990425L,
           13990424L,
           13990423L
          )
tb$dateissue %<>% as.Date()

 [1] "1399-05-08" "1399-05-07" "1399-05-06" "1399-05-05" "1399-05-04" "1399-05-01" NA          
 [8] "1399-04-30" "1399-04-29" "1399-04-28" "1399-04-25" "1399-04-24" "1399-04-23"

are these historic dates from the 14th century ?

no, it's for Solar calendar.for IRAN country

we need to understand these integer values and how they map to dates.
Are they counting days since some known date ?

In our solar calendar, we have months by 31 days.

that implies you are counting from a day0 roughly 40k years ago ?

(13990508L/31)/12
#[1] 37608.89

where did you get the values from ? can you alter the way you extract them ?

no this days are for now and not for 40 years ago.
no i can't change the value and i want to only na change to date(1399-04-31).

you say they are for now, but what is the year part of the date ?
1399 ?
you are confusing me.
1399 was 621 years ago... wasnt it ? 1399 was in the 14th century. we are in the 21st century...
what am I missing ?

for my country the start calendar is islamic and not similar other country, for this we have in year 1399 and not 2020.

That makes sense, I appreciate the explanation, but now I'm unclear on your intention

Do you want to deal with these solar dates directly, and you dont want to translate to western date, but to use directly so '1399' is a number you see in the year position while you work ?
or, do you want to take the custom date and manipulate it to treat as western? (so you see the 1399 as 2020 while you work ?)

yes i want to use directly '1399'

I think therefore you will have to handle the dates as integer triples.

(tb <- tibble::tribble(
  ~dateissue,
  13990508L,
  13990507L,
  13990506L,
  13990505L,
  13990504L,
  13990501L,
  13990431L,
  13990430L,
  13990429L,
  13990428L,
  13990425L,
  13990424L,
  13990423L
) %>% mutate(
  solar_year= floor(dateissue/1000) %>% as.integer(),
  solar_month= floor((dateissue - solar_year*1000)/100)%>% as.integer(),
  solar_day = dateissue- solar_year*1000 - solar_month*100%>% as.integer()
))

thanks, but i wnat to replace the true date by NA.

what is 'the true date' ?
if you just want a list of NA's then you dont need to look at a list of input dates...
I dont understand.
I thought your original posting said one of the dates wasn't recognised as valid so turned to NA, and you wanted a better way to work with your dates, and avoid the NA.
now you want NA's ?

the true date is "1399-04-31" that return NA when convert to date, and i want to return this date but given me NA.

you can't have that date, because R's date functions (and the packages I'm aware of are for the western calendar).
thats why I provided you the integer triple representation.
Did you notice that 1399 04 31 was reproduced there, and it had no NA's ?

there is no way to use time zone for change and give true date?

Timezones are about adjusting the hour based on difference from Greenwich meantime (or Coordinated Universal Time)...they are not alternate calendars as such, sorry (as far as I know)

Thanks @nirgrahamuk :pray:

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.