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 in Data Science by Avinash
• 1,260 points
10 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
answered Jun 24 by Sohail
• 2,960 points

Related Questions In Data Science

0 votes
0 answers

Load csv file in R

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

6 days ago in Data Science by avinash
• 940 points
3 views
0 votes
0 answers

Stepwise AIC using forward selection in R

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

Jun 24 in Data Science by Sohail
• 2,960 points
4 views
0 votes
1 answer

Converting xlsx to xls using Microsoft Office Compitablity Pack's excelcnv

Simply rearranging the positions of the parameters ...READ MORE

answered Mar 25 in Data Science by gaurav
• 13,460 points
74 views
0 votes
0 answers

Introduction to Statistical Learning with Applications in R Figure Codes

I recently bought the following book: An Introduction ...READ MORE

Jun 1 in Data Science by avinash
• 940 points
23 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,610 points
423 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
468 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
4,288 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
492 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 in Data Science by Sohail
• 2,960 points
7 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 in Data Science by Sohail
• 2,960 points
8 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP