R Language is known for Data Science and used extensively in the analysis of Data Files. To study Data first we need to import the data in R environment. R can easily read various file formats like csv, excel, table, etc. In this R Programming Tutorial I am going to show How to Read Data Files for the following formats:
- CSV File
- Table File
- Excel File
Read Also:
Steps to Import CSV Files in R Language
For the demo purpose I am going to use “Test1.csv” file with Column Names as Id, Name, Salary, and Age. To read the data use “read.csv()” function in R. Following is the example of reading CSV Files in R Programming.
To use only a specific column value use “Variable$Column_Name” Command. See the image below for example.
How to Read Excel Files in R Programming
Use read.xlsx() function to read excel files in R Programming Language. See the image below to see how it is executed in R Environment. Before you can use the function install package named “xlsx” by using the command: install.packages(“xlsx”). Once the package is installed use load the package using library(xlsx) command. Now see how to read the excel file in R below:
Steps to Read Table File in R Programming
A data table can resides in a text file. The cells inside the table are separated by blank characters. Function used to read table files is read.table(). See the following example to read Table File in R.
There are many other file formats like XML, JSON, Web Data, Database file that can be used in R. I will use each of the mentioned file as Data Source in coming tutorials.
Thank you for reading the post. Subscribe Technokarak.com for more Programming Tutorials.