I'm trying to read data into R from a text file such that I can plot it:
coupling <- read.table("~/table.format",stringsAsFactors = FALSE, sep='\t')
A row from this table looks as follows:
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
Where the columns (residue, delay, height) are separated by tabs and data within the columns is separated by ','. I would now like to plot height vs delay, so I attempt to assign the columns to variables:
xdata <- c(coupling[1,2])
ydata <- c(coupling[1,3])
However, if I try and plot plot(xdata,ydata) I get the following errors:
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
Printing xdata (and ydata) gives a variable of the form:
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 "
Presumably R can't plot this with the quotes in place. I've tried a few alternatives to try and get round this, however, none of these have worked:
newxdata <-as.numeric(xdata)
Returns error:
Warning message:
NAs introduced by coercion
Print gets me close:
print(xdata,quote=FALSE)
This seems to do the trick; the output loses the quotes:
[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
But if I assign it to a variable, the quotes reappear and I still can't plot the data:
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 "
How can I get around this problem?