data.matrix(data)中的警告:由强制[时间序列]引入NA

时间:2018-11-14 23:26:52

标签: r

从Excel的角度来看enter image description here,数据集看起来像这样

所以,这是我在包括时间序列部分之前所做的完整代码。

library(tidyverse)
library(xts)
library(fpp)
library(astsa)
library(DT)
library(dygraphs)
library(lubridate)

library(readxl)
Aust_Beer_Production <- read_excel("D:/Working Directory/monthly-beer-production-in-austr.xlsx")
Aust_Beer_Production2 <- as.data.frame(Aust_Beer_Production, stringsAsFactors = F)
names(Aust_Beer_Production2)[2] <- "MegaLiters_Monthly"

Aust_Beer_Production3 <- Aust_Beer_Production2 %>%
   mutate(Revenue = MegaLiters_Monthly * 1000 * 15)

有人知道如何防止此事件在我的R Markdown文件中弹出:

 ## Warning in data.matrix(data): NAs introduced by coercion

我正在将数据集转换为ts

Aust_Beer_TS <- ts(Aust_Beer_Production2, frequency = 12, start = c(1956,1), end = c(1990, 12))

最终结果如下enter image description here

我应该尝试通过lubridate进行转换吗?在以前的尝试中,我尝试了

Aust_Beer_Production3$Month <- as.Date(Aust_Beer_Production3$Month, "yearmon") 

但显然没有任何改变

enter image description here

我如何强行删除被强制执行的NA并纠正错误?

0 个答案:

没有答案