Documentation:Importing data in RStudio on a windows computer from CSV and text files
It can sometimes be useful to read Data in from another file using R. There are two different ways this can be accomplished using RSutdio.
To upload data from a file into Rstudio, choose one of the two methods below.
- Open R. Under the Environment tab, select the option Import dataset.
- Click The option "From textfile...".
- Find the file you wish to upload.
- Select the options that are appropriate for your file, most importantly, the separator option and the header option.
- Click submit, and R will run code for you that will upload the data into the data section of R. R will save the data to an object named after the file
- If your data has multiple columns that you entered, you can select the column you wish to plot with the following code.
Alternatively, you can manually import a document using the following code.
>mydata= read.table("c:/mydata.csv", header=TRUE)
read.table will parse CSV and txt files, the first argument is the file name and the location of the file, This must include the directories. The second argument will tell R whether the file has a header or not.
If you plan to extract multiple files from the same working directory, it may be beneficial to set the location of those files as your working directory(eg. c:/users/documents as the working directory for a file and path c:/user/documents/myfile.txt)
To do this, use the following code
>setwd("C:/Documents and Settings/username/My Documents/x/y/z")
Where the input value is the directory you wish to work from. This command will work in Rstudio, or RStat
Note: R will not be able to read files located outside your working directory.
Alternatively, you can set your working directory by clicking the session tab in the top menu->Set Working Directory->Choose Directory, and then selecting the directory you wish to work from.
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.
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 RStat on a windows computer from CSV and text files