开发者

R - CSV error - unexpected numeric constant

开发者 https://www.devze.com 2023-03-10 01:43 出处:网络
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:

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
开发者_Go百科

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


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

I think this is a simple problem of data processing.


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)
0

精彩评论

暂无评论...
验证码 换一张
取 消