Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R - CSV error - unexpected numeric constant

Tags:

r

csv

I have a simple csv file with around 20K+ values separated by commas. When I try to load the values in R, it gives me the error:

r:3: unexpected numeric constant

Here is the simple command of R that I executed

someThing <- c(0.080172405,0.06233087,0.04315185,0.0652015,0.03201301.......n)
n= 70,000 values

I cannot copy paste all the 20K+ values here. I googled this error and there is no special character or another thing except for some floating values.

EDIT

http://pastebin.com/FVkUV6kY

like image 862
user751637 Avatar asked Jun 02 '11 00:06

user751637


2 Answers

The 5682-th entry is "0.0733 7422182", which has a space.

I think this is a simple problem of data processing.

like image 109
Triad sou. Avatar answered Oct 13 '22 01:10

Triad sou.


There's a newline partway through the file, which is causing that section to look something like (replacing that newline with a space) and so after the space, there's an unexpected numeric constant.

... 0.0068243323,0.0733 7422182,0.07379706 ...

Here's how I found it:

b <- scan(file, what=character(0))
length(b)

The length is 2, not 1.

It can be read in as is like this:

b <- paste(b, collapse="")
b <- substring(b, 3, nchar(b)-1)
b <- strsplit(b,",")[[1]]
b2 <- as.numeric(b)
like image 32
Aaron left Stack Overflow Avatar answered Oct 13 '22 01:10

Aaron left Stack Overflow