💡 Learn from AI

Introduction to R Programming

Lesson 4: Data Import and Export in R

Data Import and Export are essential parts of data analysis. R provides several functions to import and export data in various formats.

Importing Data

In R, you can use the read.table() function to import data from a text file. The read.csv() function is a faster and more convenient way to import data stored in a comma-separated file. Similarly, the read.xlsx() function is used to import data from an Excel file.

Exporting Data

To export data from R, you can use the write.table(), write.csv(), and write.xlsx() functions. These functions allow you to export data into various formats, including text files, comma-separated files, and Excel files.

Recommended Reading

  1. Data Import/Export - RStudio

  2. Data Import/Export - CRAN

  3. Importing and Exporting Data in R

Examples

Here is an example of importing a CSV file in R:

my_data <- read.csv("path/to/my/file.csv")

Similarly, here is an example of exporting data to a CSV file:

write.csv(my_data, "path/to/my/file.csv")
Take quiz (5 questions)

Previous unit

Lesson 3: Data Structures in R

Next unit

Lesson 5: Data Manipulation in R

All courses were automatically generated using OpenAI's GPT-3. Your feedback helps us improve as we cannot manually review every course. Thank you!