How to load a dataset in R language?

In R language, there are several commonly used methods for loading datasets:

  1. You can utilize the built-in datasets in R by directly calling on them. For example, to load the iris dataset, you can use the following command:
data(iris)
  1. Load data from an external file in standard format using the read.table() or read.csv() functions. For example, if the data file is named “data.csv,” you can load the data using the following command:
data <- read.csv("data.csv")
  1. Utilize external data files in different formats: If the data is stored in external files in different formats, you can use the corresponding functions to load the data. For example, if the data is stored in an Excel file, you can use the read_excel() function from the readxl package to load the data. Assuming the data file is named “data.xlsx”, you can use the following command to load the data:
library(readxl)
data <- read_excel("data.xlsx")
  1. Utilize datasets provided by other packages: Many R packages come with their own datasets that can be loaded using the data() function. For example, to load the dataset “MASS::Boston” from the MASS package, you can use the following command:
data("Boston", package = "MASS")

Regardless of the method used, after loading the dataset, you can use the head() function to check the first few rows to make sure the data has been loaded correctly. For example:

head(data)
bannerAds