#A dataset call "charDate" , class is "character"
charDate
[1] "2017-01-19" "42431" "42455" "42430" "2017-01-08" "2017-01-08"
将as.Date
应用于origin ="1900-01-01
后,其成为NA
as.Date.character(charDate, origin = "1900-01-01")
[1] "2017-01-19" NA NA NA "2017-01-08" "2017-01-08"
如何避免它成为NA
?
答案 0 :(得分:1)
我们可以分两步完成。首先,在OP的帖子中转换'charDate',我们得到数字元素的NA。子集来自“charDate”中与“new”(--my_long_calculation = (FLOOR(DATEPART(DAY, DATEADD(MINUTE, [table1].someInt, [table1].someDate)) / 1440.0) % 2) + 1
SELECT
[table1].ID
FROM
[table1]
INNER JOIN
[table2] ON [table2].someattribute = my_long_calculation
INNER JOIN
[table3] ON [User].someattribute = my_long_calculation
WHERE
my_long_calculation = 1
)中的NA元素对应的元素,将其转换为is.na
类,然后执行numeric
as.Date
new <- as.Date(charDate, origin = "1900-01-01")
new[is.na(new)] <- as.Date(as.numeric(charDate[is.na(new)]), origin = "1900-01-01")
new
#[1] "2017-01-19" "2016-03-04" "2016-03-28" "2016-03-03" "2017-01-08" "2017-01-08"