【发布时间】:2015-08-13 07:41:00
【问题描述】:
我正在尝试将数据从文本文件读入 R 以便我可以绘制它:
coupling <- read.table("~/table.format",stringsAsFactors = FALSE, sep='\t')
该表中的一行如下所示:
133 0.0116, 0.0226, 0.0236, 0.0244, 0.0264, 0.0124, 0.013, 0.014, 0.0158, 0.034, 0.0348, 0.0356, 0.0372 329777.0, -236464.0, -348470.0, -554708.0, -471896.0, 538782.0, 695291.0, 812729.0, 983141.0, 208212.0, 214012.0, 366636.0, 343232.0
列(残差、延迟、高度)由制表符分隔,列中的数据由“,”分隔。我现在想绘制高度与延迟,所以我尝试将列分配给变量:
xdata <- c(coupling[1,2])
ydata <- c(coupling[1,3])
但是,如果我尝试绘制 plot(xdata,ydata) 我会收到以下错误:
Error in plot.window(...) : need finite 'xlim' values
In addition: Warning messages:
1: In xy.coords(x, y, xlabel, ylabel, log) : NAs introduced by coercion
2: In xy.coords(x, y, xlabel, ylabel, log) : NAs introduced by coercion
3: In min(x) : no non-missing arguments to min; returning Inf
4: In max(x) : no non-missing arguments to max; returning -Inf
5: In min(x) : no non-missing arguments to min; returning Inf
6: In max(x) : no non-missing arguments to max; returning -Inf
打印 xdata(和 ydata)会给出形式如下的变量:
xdata
[1] "0.0116, 0.0226, 0.0236, 0.0244, 0.0264, 0.0124, 0.013, 0.014, 0.0158, 0.034, 0.0348, 0.0356, 0.0372 "
大概 R 不能用引号来绘制这个。我已经尝试了一些替代方案来尝试解决这个问题,但是,这些都没有奏效:
newxdata <-as.numeric(xdata)
返回错误:
Warning message:
NAs introduced by coercion
打印让我接近:
print(xdata,quote=FALSE)
这似乎可以解决问题;输出丢失引号:
[1] 0.0116, 0.0226, 0.0236, 0.0244, 0.0264, 0.0124, 0.013, 0.014, 0.0158, 0.034, 0.0348, 0.0356, 0.0372
但是如果我将它分配给一个变量,引号会重新出现,我仍然无法绘制数据:
newxdata <- c(print(xdata,quote=FALSE))
newxdata
[1] "0.0116, 0.0226, 0.0236, 0.0244, 0.0264, 0.0124, 0.013, 0.014, 0.0158, 0.034, 0.0348, 0.0356, 0.0372 "
我该如何解决这个问题?
【问题讨论】: