Categories: R Series

How to Read data in Rstudio?

R is capable of reading data from most formats, including files created in other statistical packages. Whether the data was prepared using Excel (in CSV, XLSX, or TXT format), R can read and load the data into memory.

R also has two native data formats Rdata (sometimes shortened to Rda) and Rds. 

Before reading any data in Rstudio you first need to check that you are in the same directory that as of the Data you want to load.

> getwd()
[1] "C:/Users/Admin/Desktop"
> setwd("C:/Users/Admin/Desktop/zogya_d")  # the data is present in the folder name zigya_d

Reading Local .txt file

Function: read.table()

Common Parameters:

  • Header: TRUE when the first row includes variable names. The default is FALSE.
  • Sep: A string indicating what is separating the data. The default is ”  “.

To import a word.txt file from your local, the syntax would be:

# Read a txt file, named "mtcars.txt"
 and storing it in vector named my_data
> my_data <- read.tabe("word.txt", header=TRUE, sep= " ")

By default numeric items (except row labels) are read as numeric variables. We can change this if we want.

Reading Local .csv file

Function: read.csv()

Common Parameters:

  • Header: TRUE when first row includes variable names. The default is FALSE.
# Read a csv file, named "word.csv"
 and storing it in vector named my_data
> my_data <- read.csv("word.csv")

Conclusion

We covered how to read data from .txt files and .csv files as well, along with the change the directory in which the data is present.

This brings the end of this Blog. We really appreciate your time.

Hope you liked it.

Do visit our page www.zigya.com/blog for more informative blogs on Data Science

Keep Reading! Cheers!

Zigya Academy
BEING RELEVANT

Zigya Acadmey

Share
Published by
Zigya Acadmey

Recent Posts

Understanding Standard Form of Numbers: An Explanation With Examples

Through the standard form offers different advantages in mathematical calculations and scientific notation. Firstly, it…

5 months ago

How to deal with stress and anxiety in college

Introduction Stress is a feeling caused by an external trigger that makes us frustrated, such…

6 months ago

Why is Sociology Important These Days?

Sociology is a broad discipline that examines societal issues. It looks at the meaningful patterns…

6 months ago

How to Convert Inches to mm

Some info about Inch Inches are a unique measure that persuades us that even the…

8 months ago

Antilogarithms – Definition, Methods, and Examples

You should be familiar with logarithms to understand antilogarithms in a better manner. Logarithms involve…

10 months ago

नाटककार सुरेंद्र वर्मा

यहां "नाटककार सुरेंद्र वर्मा" पुस्तक की पीडीएफ विद्यार्थी, शोधार्थी और जो इसका अभ्यास के लिए…

10 months ago