Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I import a CSV file in R? [closed]

Tags:

import

r

csv

I have a .csv file in my workstation. How can I open that file in R and do statistical calculation?

like image 246
Uselesssss Avatar asked Nov 07 '12 07:11

Uselesssss


People also ask

How do I open a CSV file in R on Mac?

In order to find the location of the file on Mac OS you can right click on the file and choose "Get Info"; on Windows you can right click on the file and choose "Properties". Use this local path in the file path in the read. csv() command to import the file.

What function is used for importing CSV files in R?

The read. csv() method in base R is used to load a . csv file into the present script and work with it. The contents of the csv can be stored into the variable and further manipulated.


1 Answers

You would use the read.csv function; for example:

dat = read.csv("spam.csv", header = TRUE)

You can also reference this tutorial for more details.

Note: make sure the .csv file to read is in your working directory (using getwd()) or specify the right path to file. If you want, you can set the current directory using setwd.

like image 143
Paul Hiemstra Avatar answered Oct 08 '22 00:10

Paul Hiemstra