我正在尝试在数据集中绘制几个参数。但是,当我尝试绘图时会出现无穷大错误。
看起来像应用complete.cases或制作一个新的数据帧会将range
更改为-Inf
和Inf
。为什么是这样?如何更改它,使范围是有限的数并可以绘制?
analysis <- function(){
#input file
input_df<-read.csv("Book1.csv")
dput(head(input_df))
print(range(input_df$Forecast_Error))
print(range(input_df$YYZ.Toronto.Observed.Temp))
#create new data file with forecast errors
#input2_df <- input_df[,c(10,14)]
input2_df <- data.frame(input_df$Forecast_Error, input_df$YYZ.Toronto.Observed.Temp)
print(range(input2_df$Forecast_Error))
print(range(input2_df$YYZ.Toronto.Observed.Temp))
input2_df <- input2_df[complete.cases(input2_df), ]
print(range(input2_df$Forecast_Error))
print(range(input2_df$YYZ.Toronto.Observed.Temp))
write.table(input2_df,"test.txt")
plot(input2_df$Forecast_Error, input2_df$YYZ.Toronto.Observed.Temp, main="Toronto Observed Temp vs Forecast Error",
xlab="Forecast error", ylab="Toronto observed Temp", pch=19)
}
输出:
source('PeakMissAnalysis.R') analysis()
structure(list(Date = c(43191.95833, 43191.91667, 43191.875,
43191.83333, 43191.79167, 43191.75), year = c(2018L, 2018L, 2018L,
2018L, 2018L, 2018L), month = c(4L, 4L, 4L, 4L, 4L, 4L), day = c(1L,
1L, 1L, 1L, 1L, 1L), hour = 24:19, Forecast_Error = c(-132.55,
-141.36, -255.57, -180.2, -461.28, -359.09), YYZ.Toronto.Observed.Temp = c(-0.2,
-0.3, -1, -0.7, -0.4, 0.2)), row.names = c(NA, 6L), class = "data.frame")
[1] -866.75 397.00
[1] -3.4 7.1
[1] Inf -Inf
[1] Inf -Inf
[1] Inf -Inf
[1] Inf -Inf
Error in plot.window(...) : need finite 'xlim' values
In addition: There were 12 warnings (use warnings() to see them)
这是数据的屏幕截图 Screen shot of data
答案 0 :(得分:0)
我相信这是怎么回事。当您使用
创建input2_df时models = responses.map((response) =>
new Model ({ id: response.userId, name: response.userName })
);
新数据框的名称为 not Forecast_Error和YYZ.Toronto.Observed.Temp,它们分别是input_df.Forecast_Error和input_df.YYZ.Toronto.Observed.Temp; data.frame函数不知道您要如何调用这些变量。会更好
input2_df <- data.frame(input_df$Forecast_Error, input_df$YYZ.Toronto.Observed.Temp)
现在,新名称将是您所期望的。当我在最后一个range语句中对其进行测试时,此解决方案就起作用了。