as.Date yields NA for month name “März” (march)

前端 未结 3 952
挽巷
挽巷 2021-01-20 05:46

I got a scraped character vector with dates. My problem: When using as.Date(), every date containing the month name \"März\" (= which means \"march\" in German)

3条回答
  •  时光取名叫无心
    2021-01-20 06:23

    I could reproduce this on Windows 7 x64. There are many issues with how R and Windows interact with character encoding, and I don't pretend to understand them. In your case, simply converting to latin1 encoding before converting to a Date should work.

    as.Date(iconv(dates,from='UTF-8',to='latin1'),'%d. %B %Y')
    #  [1] "2009-02-12" "2006-11-12" "2010-03-19" "2007-06-30" "2006-03-07" "2007-03-19"
    #  [7] "2006-01-22" "2005-09-24" "2012-02-15" "2007-03-28"
    

    There might be a way to get as.Date to recognize different encodings in Windows, but I don't know it.

提交回复
热议问题