Documentation:Importing data in RStat on a windows computer from CSV and text files

From UBC Wiki

It can sometimes be useful to read Data in from another file using R. There are a few different ways this can be accomplished using both Rstat and Rstudio. The two types of files discussed in this article are CSV and txt files.

If you plan to use Rstat instead of Rstudio, you must manually script R to import data from a file. To script txt and CSV files use the following code.
>mydata=read.table("myfile.csv", header=TRUE)

-The first argument is the directory and name of the file, the second argument tells R if there is a header or not. This code will save the data to a variable named mydata.

RStat user interface


If you do not want to input the entire file name and directory, you can change your working directory. This can be done using the code setwd("c:/users/username/x/y/z") where x/y/z is the directory route to the location of the files.

Alternatively, you can automatically change the directory by going to file->change dir and manually selecting the directory you wish to work from. A video of this is shown below.


To check data that has already been parsed into R type the name of the variable that you saved the data to (eg. type mydata to view the data) or if you want to view a single column of the data, type the variable name, followed by [#], where # is the number of the column you wish to view.

You may also be interested in these links

Documentation:Importing data in RStudio on a mac computer from text and CSV files
Documentation:Importing data in RStudio on a windows computer from excel files ‎
Documentation:Importing data in RStat on a mac computer from text and CSV files
Documentation:Importing data in RStat on a mac computer from excel files‎
Documentation:Importing data in RStudio on a mac computer from excel files
Documentation:Importing data in RStat on a windows computer from excel files ‎
Documentation:Importing data in RStudio on a windows computer from CSV and text files