What Is The Data() Function In R?
Last Updated :
18 Apr, 2024
In this article, we will discuss what is data function and how it works in R Programming Language and also see all the available datasets in R.
Data() Function In R
In R, the data() function is used to load datasets that come pre-installed with R packages or datasets that have been explicitly installed into your R environment. These datasets are typically included to provide users with example data for practicing data analysis, visualization, and statistical modeling. The data() function allows you to load these datasets into your R session for exploration and analysis.
The basic syntax of the data() function is:
data(dataset_name)
dataset_name is the name of the dataset you want to load.
R
# list of all the dataset
data()
Output:
Data sets in package ‘caret’:
GermanCredit German Credit Data
Sacramento Sacramento CA Home Prices
absorp (tecator) Fat, Water and Protein Content of Meat Samples
bbbDescr (BloodBrain) Blood Brain Barrier Data
cars Kelly Blue Book resale data for 2005 model year
GM cars
cox2Class (cox2) COX-2 Activity Data
cox2Descr (cox2) COX-2 Activity Data
cox2IC50 (cox2) COX-2 Activity Data
dhfr Dihydrofolate Reductase Inhibitors Data
endpoints (tecator) Fat, Water and Protein Content of Meat Samples
fattyAcids (oil) Fatty acid composition of commercial oils
logBBB (BloodBrain) Blood Brain Barrier Data
mdrrClass (mdrr) Multidrug Resistance Reversal (MDRR) Agent Data
mdrrDescr (mdrr) Multidrug Resistance Reversal (MDRR) Agent Data
oilType (oil) Fatty acid composition of commercial oils
potteryClass (pottery) Pottery from Pre-Classical Sites in Italy
scat Morphometric Data on Scat
scat_orig (scat) Morphometric Data on Scat
segmentationData Cell Body Segmentation
Data sets in package ‘circular’:
fisherB1 B.1 Arrival times at an intensive care unit
fisherB10 B.10 Directions of desert ants
fisherB10c B.10 Directions of desert ants
fisherB11 B.11 Movements of sea stars
fisherB11c B.11 Movements of sea stars
fisherB12 B.12: Vanishing directions of homing pigeons
fisherB12c B.12: Vanishing directions of homing pigeons
fisherB13 B.13: Orientations of termite mounds
fisherB13c B.13: Orientations of termite mounds
fisherB18 B.18 Wind direction and ozone concentration.
fisherB18c B.18 Wind direction and ozone concentration.
fisherB1c B.1 Arrival times at an intensive care unit
fisherB2 B.2 Measurements of long-axis orientation of 133
feldspar laths in basalt
fisherB20 B.20 Movements of blue periwinkles.
fisherB20c B.20 Movements of blue periwinkles.
fisherB2c B.2 Measurements of long-axis orientation of 133
feldspar laths in basalt
fisherB3 B.3 Movements of turtles
fisherB3c B.3 Movements of turtles
fisherB4 B.4 Directional preferences of starhead
topminnows
fisherB4c B.4 Directional preferences of starhead
topminnows
fisherB5 B.5 Measurements of long-axis orientation of 164
feldspar laths in basalt
fisherB5c B.5 Measurements of long-axis orientation of 164
feldspar laths in basalt
fisherB6 B.6 Cross-bed azimuths of palaeocurrents
fisherB6c B.6 Cross-bed azimuths of palaeocurrents
fisherB7 B.7 Movements of ants
fisherB7c B.7 Movements of ants
fisherB8 B.8 Orientations of pebbles
fisherB8c B.8 Orientations of pebbles
fisherB9 B.9 Dance directions of bees
fisherB9c B.9 Dance directions of bees
fisherB9direction (fisherB9)
B.9 Dance directions of bees
fisherB9frequency (fisherB9)
B.9 Dance directions of bees
ncfrog Northern Cricket Frog
ncfrog.rad (ncfrog) Northern Cricket Frog
pigeons Initial orientation of displaced homing pigeons
rao.table Table for Rao's Spacing Test of Uniformity
swallows Orientation of juvenile barn swallows
turtles Arrival directions of displaced sea turtles
wind Col De La Roa wind direction
x.coope (coope) Coope dataset
y.coope (coope) Coope dataset
Data sets in package ‘datasets’:
AirPassengers Monthly Airline Passenger Numbers 1949-1960
BJsales Sales Data with Leading Indicator
BJsales.lead (BJsales) Sales Data with Leading Indicator
BOD Biochemical Oxygen Demand
CO2 Carbon Dioxide Uptake in Grass Plants
ChickWeight Weight versus age of chicks on different diets
DNase Elisa assay of DNase
EuStockMarkets Daily Closing Prices of Major European Stock
Indices, 1991-1998
Formaldehyde Determination of Formaldehyde
HairEyeColor Hair and Eye Color of Statistics Students
Harman23.cor Harman Example 2.3
Harman74.cor Harman Example 7.4
Indometh Pharmacokinetics of Indomethacin
InsectSprays Effectiveness of Insect Sprays
JohnsonJohnson Quarterly Earnings per Johnson & Johnson Share
LakeHuron Level of Lake Huron 1875-1972
LifeCycleSavings Intercountry Life-Cycle Savings Data
Loblolly Growth of Loblolly pine trees
Cities
VADeaths Death Rates in Virginia (1940)
WWWusage Internet Usage per Minute
WorldPhones The World's Telephones
ability.cov Ability and Intelligence Tests
airmiles Passenger Miles on Commercial US Airlines,
1937-1960
airquality New York Air Quality Measurements
anscombe Anscombe's Quartet of 'Identical' Simple Linear.............................................................
When you use the data() function without any arguments, it displays a list of available datasets that are pre-installed with R packages. You can then load a specific dataset by providing its name as an argument to the data() function.
R
# Load a specific dataset (e.g., 'iris')
data(iris)
# Display the first few rows of the dataset
head(iris)
Output:
Sepal.Length Sepal.Width Petal.Length Petal.Width Species
1 5.1 3.5 1.4 0.2 setosa
2 4.9 3.0 1.4 0.2 setosa
3 4.7 3.2 1.3 0.2 setosa
4 4.6 3.1 1.5 0.2 setosa
5 5.0 3.6 1.4 0.2 setosa
6 5.4 3.9 1.7 0.4 setosa
In this example, we use the data() function to load the “iris” dataset. Once loaded, we display the first few rows of the dataset using the head() function to inspect its structure and contents.
Similar like this we will also take some other datset and use them.
R
data(mtcars)
head(mtcars)
Output:
mpg cyl disp hp drat wt qsec vs am gear carb
Mazda RX4 21.0 6 160 110 3.90 2.620 16.46 0 1 4 4
Mazda RX4 Wag 21.0 6 160 110 3.90 2.875 17.02 0 1 4 4
Datsun 710 22.8 4 108 93 3.85 2.320 18.61 1 1 4 1
Hornet 4 Drive 21.4 6 258 110 3.08 3.215 19.44 1 0 3 1
Hornet Sportabout 18.7 8 360 175 3.15 3.440 17.02 0 0 3 2
Valiant 18.1 6 225 105 2.76 3.460 20.22 1 0 3 1
Conclusion
The data() function in R is a convenient way to load pre-installed datasets that come with R packages or datasets that have been installed separately. By using this function, you can quickly access example data for practicing data analysis techniques and exploring various statistical methods in R.
Share your thoughts in the comments
Please Login to comment...