r - convert factor to date with empty cells -


i have factor vector x looking this:

"" "1992-02-13" "2011-03-10" "" "1998-11-30" 

can convert vector date vector (using as.date())?

trying obvious way gives me:

> x <- as.date(x) error in chartodate(x) : character string not in standard unambiguous format 

at moment solve problem this:

> levels(x)[1] <- na > x <- as.date(x) 

but doesn't elegant...

thank in advance!

you need tell as.date format expect in character vector:

xd <- as.date(x, format="%y-%m-%d") xd [1] na           "1992-02-13" "2011-03-10" na           "1998-11-30"  illustrate these indeed dates: xd[3] - xd[2] time difference of 6965 days 

ps. conversion using as.date works regardless of whether data character vector or factor.


Comments

Popular posts from this blog

jQuery Ajax Render Fragments OR Whole Page -

javascript - Iterate over array and calculate average values of array-parts -

ASP.NET Javascript: window.open won't work twice -