as.Date在从字符转换时返回NA

时间:2017-03-22 06:21:42

标签: r

我正在将以下格式转换为字符

  January 2016

我想将其转换为以下格式

   201601

我正在使用以下代码

    df$date <- as.Date(df$date,"%B %Y")

但是它返回了NA值。我甚至将语言环境设置如下

    lct<- Sys.getlocale("LC_TIME")
    Sys.setlocale("LC_TIME",lct)

但它给了我NA值。如何解决它

1 个答案:

答案 0 :(得分:2)

我们可以使用collectionif ($config['type'] == 'collection') { $template = $options['template']; unset($options['template']); $options['type'] = new RuntimeFormType($config["name"], $template); $form->add($themeConfig["name"], $themeConfig["type"], $options); }

轻松完成此操作
as.yearmon

如果我们按format路线行驶,那么&#39;日期&#39;也需要一天,所以,每天library(zoo) format(as.yearmon(str1), "%Y%m") #[1] "201601" ,然后在转换为&#39;日期后使用as.Date

paste

数据

format
相关问题