简体   繁体   中英

How read csv files with comma (,) as separators in R

I'm trying to read this csv file in R. (scores.csv)

ALVO,P,Prediction,fold
1,0.9079557994069131,"1",0
1,0.4323657303144317,"0",0
1,0.9944246408740756,"1",0
1,0.8025072441292207,"1",0
1,0.8687043760021418,"1",0
1,0.8728815023271057,"1",0
1,0.9998157504312343,"1",0
1,0.6610699528239422,"1",0
1,0.9994385364719802,"1",0

I've tried this:

result <- read.csv("C:/scores.csv", header = TRUE, sep = ",", quote = "\\"")

AND THIS:

result <- read.csv("C:/scores.csv")

It's not working, I'm getting the P,Prediction,fold with NA values

head(result)

but I got this:

                        ALVO  P Prediction fold
1 1,0.9079557994069131,"1",0 NA         NA   NA
2 1,0.4323657303144317,"0",0 NA         NA   NA
3 1,0.9944246408740756,"1",0 NA         NA   NA
4 1,0.8025072441292207,"1",0 NA         NA   NA
5 1,0.8687043760021418,"1",0 NA         NA   NA
6 1,0.8728815023271057,"1",0 NA         NA   NA

Someone already have done that?

please help!

Unix cat output is below:

> cat input.csv 
ALVO,P,Prediction,fold
1,0.9079557994069131,"1",0
1,0.4323657303144317,"0",0
1,0.9944246408740756,"1",0
1,0.8025072441292207,"1",0
1,0.8687043760021418,"1",0
1,0.8728815023271057,"1",0
1,0.9998157504312343,"1",0
1,0.6610699528239422,"1",0
1,0.9994385364719802,"1",0

R output is below:

read.csv('input.csv')
  ALVO         P Prediction fold
1    1 0.9079558          1    0
2    1 0.4323657          0    0
3    1 0.9944246          1    0
4    1 0.8025072          1    0
5    1 0.8687044          1    0
6    1 0.8728815          1    0
7    1 0.9998158          1    0
8    1 0.6610700          1    0
9    1 0.9994385          1    0

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM