在R中创建时间序列图时出错:plot.window(xlim,ylim,log,...)中的错误:需要有限的'ylim'值 [英] Error while creating a Timeseries plot in R: Error in plot.window(xlim, ylim, log, ...) : need finite 'ylim' values

查看:2792
本文介绍了在R中创建时间序列图时出错:plot.window(xlim,ylim,log,...)中的错误:需要有限的'ylim'值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里是我的单列数据集的示例:

Here's a sample of my single column data set:

Lines 
141,523
146,785
143,667
65,560
88,524
148,422

我读了这篇文件作为.csv文件,将其转换为ts对象,然后将其绘制:

I read this file as a .csv file, convert it into a ts object and then plot it:

##Read the actual number of lines CSV file

Aclines <- read.csv(file.choose(), header=T, stringsAsFactors = F)

Aclinests <- ts(Aclines[,1], start = c(2013), end = c(2015), frequency = 52)

plot(Aclinests, ylab = "Actual_Lines", xlab = "Time", col = "red")

我收到以下错误消息:

Error in plot.window(xlim, ylim, log, ...) : need finite 'ylim' values
In addition: Warning messages:
1: In xy.coords(x, NULL, log = log) : NAs introduced by coercion
2: In min(x) : no non-missing arguments to min; returning Inf
3: In max(x) : no non-missing arguments to max; returning -Inf

我认为这可能是因为列中的,并尝试使用明智地按照这里的建议进行处理:

I thought this might be because of the "," in the columns and tried to use sapply to take care of that as advised here:

需要有限的 ylim值-错误

plot(sapply(Aclinests, function(x)gsub(",",".",x)))

但是我遇到了以下错误:

But I got the following error:

Error in plot(sapply(Aclinests, function(x) gsub(",", ".", x))) : 
  error in evaluating the argument 'x' in selecting a method for function 'plot': Error in sapply(Aclinests, function(x) gsub(",", ".", x)) : 
  'names' attribute [105] must be the same length as the vector [1]

我的原始数据集和ts数据集的标题(如果有帮助的话):

Here is the head of my original and ts data set if it might help:

> head(Aclines)
    Lines
1 141,523
2 146,785
3 143,667
4  65,560
5  88,524
6 148,422
> head(Aclinests)
[1] "141,523" "146,785" "143,667" "65,560"  "88,524"  "148,422"

此外,如果我将.csv文件读取为:

Also, if I read the .csv file as:

Aclines <- read.csv(file.choose(), header=T, **stringsAsFactors = T**)

然后我可以绘制ts对象,但是 head(Aclinests)给出以下与我的原始数据不一致的输出:

Then, I am able to plot the ts object, but head(Aclinests)gives the below output which is not consistent with my original data:

> head(Aclinests)
[1] 14 27 17 84 88 36

请咨询如何我可以画出这个ts对象。

Please advice on how I can plot this ts object.

推荐答案

避免这种情况的最简单方法是删除包含数据的excel文件中的逗号。可以使用简单的excel命令来完成,并且对我有用。

The simplest way to avoid this, in my case, is to remove the commas in the excel file containing the data. This can be done using simple excel commands and it worked for me.

这篇关于在R中创建时间序列图时出错:plot.window(xlim,ylim,log,...)中的错误:需要有限的'ylim'值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆