Import CSV file using R

0 votes
I'm attempting to import a csv file into Excel.

However I keep receiving this error message when I use data = read.csv(C:UsersldayzOneDriveDocumentsrating)

"data = read.csv(C:Users)" fails with an unexpected symbol.

The files directory was copied from details, so it should be correct. Is there anything I'm missing here?
Jun 19, 2022 in Data Science by Avinash
• 1,260 points
1,071 views

1 answer to this question.

0 votes

If there are quotes ("), by using the code in the OP's post

str(read.csv("devices.csv",sep=",",header = TRUE))
#'data.frame':  2 obs. of  1 variable:
#$ A.B.C.D.E: Factor w/ 2 levels "1,2,3,4,5","6,7,8,9,10": 1 2

We could remove the " with gsub after reading the data with readLines and then use read.table

read.csv(text=gsub('"', '', readLines('devices.csv')), sep=",", header=TRUE)
#  A B C D  E
#1 1 2 3 4  5
#2 6 7 8 9 10

Another option if we are using linux would be to remove quotes with awk and pipe with read.csv

  read.csv(pipe("awk  'gsub(/\"/,\"\",$1)' devices.csv")) 
  #  A B C D  E
  #1 1 2 3 4  5
  #2 6 7 8 9 10

Unleash the power of data with our comprehensive Data Science Training.

answered Jun 24, 2022 by Sohail
• 3,040 points

Related Questions In Data Science

0 votes
0 answers

Load csv file in R

Is it possible to import a csv ...READ MORE

Jun 27, 2022 in Data Science by avinash
• 1,840 points
332 views
0 votes
0 answers

How to read a csv-file from an url in R?

I'm not very experienced with R, so ...READ MORE

Jul 22, 2022 in Data Science by avinash
• 1,840 points
667 views
0 votes
0 answers

Stepwise AIC using forward selection in R

In R, I'm attempting to perform a ...READ MORE

Jun 24, 2022 in Data Science by Sohail
• 3,040 points
443 views
0 votes
0 answers

Read an Excel file directly from a R script

How do I open an Excel file ...READ MORE

Jul 9, 2022 in Data Science by avinash
• 1,840 points
315 views
0 votes
1 answer

Big Data transformations with R

Dear Koushik, Hope you are doing great. You can ...READ MORE

answered Dec 18, 2017 in Data Analytics by Sudhir
• 1,570 points
1,050 views
0 votes
2 answers

Transforming a key/value string into distinct rows in R

We would start off by loading the ...READ MORE

answered Mar 26, 2018 in Data Analytics by Bharani
• 4,660 points
1,227 views
0 votes
1 answer

Finding frequency of observations in R

You can use the "dplyr" package to ...READ MORE

answered Mar 26, 2018 in Data Analytics by Bharani
• 4,660 points
5,912 views
0 votes
1 answer

Left Join and Right Join using "dplyr"

The below is the code to perform ...READ MORE

answered Mar 27, 2018 in Data Analytics by Bharani
• 4,660 points
1,158 views
0 votes
1 answer

Add two lines on graph using abline in R

I am using "y 0+x" to fit ...READ MORE

answered Jun 24, 2022 in Data Science by Sohail
• 3,040 points
612 views
0 votes
1 answer

How to implement Knn-algorithm without using k-nn function in r?

I created an example that demonstrates the ...READ MORE

answered Jun 24, 2022 in Data Science by Sohail
• 3,040 points
490 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP