- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to get the list of data sets available in base R or in a package in R?
There are many data sets available in base R and in different packages of R. The characteristics of these data sets are very different, for example, some data sets are time series data, some have only numerical columns, some have numerical as well as factor columns, some includes character columns with other type of columns. Therefore, it becomes helpful to everyone who want to learn the use of R programming. To get the list of available data sets in base R we can use data() but to get the list of data sets available in a package we first need to load that package then data() command shows the available data sets in that package. Also, for data sets in base R, we can use ls("package:datasets").
Example
> data()
Output
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 Nile Flow of the River Nile Orange Growth of Orange Trees OrchardSprays Potency of Orchard Sprays PlantGrowth Results from an Experiment on Plant Growth Puromycin Reaction Velocity of an Enzymatic Reaction Seatbelts Road Casualties in Great Britain 1969-84 Theoph Pharmacokinetics of Theophylline Titanic Survival of passengers on the Titanic ToothGrowth The Effect of Vitamin C on Tooth Growth in Guinea Pigs UCBAdmissions Student Admissions at UC Berkeley UKDriverDeaths Road Casualties in Great Britain 1969-84 UKgas UK Quarterly Gas Consumption USAccDeaths Accidental Deaths in the US 1973-1978 USArrests Violent Crime Rates by US State USJudgeRatings Lawyers' Ratings of State Judges in the US Superior Court USPersonalExpenditure Personal Expenditure Data UScitiesD Distances Between European Cities and Between US 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 Regressions attenu The Joyner-Boore Attenuation Data attitude The Chatterjee-Price Attitude Data austres Quarterly Time Series of the Number of Australian Residents beaver1 (beavers) Body Temperature Series of Two Beavers beaver2 (beavers) Body Temperature Series of Two Beavers cars Speed and Stopping Distances of Cars chickwts Chicken Weights by Feed Type co2 Mauna Loa Atmospheric CO2 Concentration crimtab Student's 3000 Criminals Data discoveries Yearly Numbers of Important Discoveries esoph Smoking, Alcohol and (O)esophageal Cancer euro Conversion Rates of Euro Currencies euro.cross (euro) Conversion Rates of Euro Currencies eurodist Distances Between European Cities and Between US Cities faithful Old Faithful Geyser Data fdeaths (UKLungDeaths) Monthly Deaths from Lung Diseases in the UK freeny Freeny's Revenue Data freeny.x (freeny) Freeny's Revenue Data freeny.y (freeny) Freeny's Revenue Data infert Infertility after Spontaneous and Induced Abortion iris Edgar Anderson's Iris Data iris3 Edgar Anderson's Iris Data islands Areas of the World's Major Landmasses ldeaths (UKLungDeaths) Monthly Deaths from Lung Diseases in the UK lh Luteinizing Hormone in Blood Samples longley Longley's Economic Regression Data lynx Annual Canadian Lynx trappings 1821-1934 mdeaths (UKLungDeaths) Monthly Deaths from Lung Diseases in the UK morley Michelson Speed of Light Data mtcars Motor Trend Car Road Tests nhtemp Average Yearly Temperatures in New Haven nottem Average Monthly Temperatures at Nottingham, 1920-1939 npk Classical N, P, K Factorial Experiment occupationalStatus Occupational Status of Fathers and their Sons precip Annual Precipitation in US Cities presidents Quarterly Approval Ratings of US Presidents pressure Vapor Pressure of Mercury as a Function of Temperature quakes Locations of Earthquakes off Fiji randu Random Numbers from Congruential Generator RANDU rivers Lengths of Major North American Rivers rock Measurements on Petroleum Rock Samples sleep Student's Sleep Data stack.loss (stackloss) Brownlee's Stack Loss Plant Data stack.x (stackloss) Brownlee's Stack Loss Plant Data stackloss Brownlee's Stack Loss Plant Data state.abb (state) US State Facts and Figures state.area (state) US State Facts and Figures state.center (state) US State Facts and Figures state.division (state) US State Facts and Figures state.name (state) US State Facts and Figures state.region (state) US State Facts and Figures state.x77 (state) US State Facts and Figures sunspot.month Monthly Sunspot Data, from 1749 to "Present" sunspot.year Yearly Sunspot Data, 1700-1988 sunspots Monthly Sunspot Numbers, 1749-1983 swiss Swiss Fertility and Socioeconomic Indicators (1888) Data treering Yearly Treering Data, -6000-1979 trees Diameter, Height and Volume for Black Cherry Trees uspop Populations Recorded by the US Census volcano Topographic Information on Auckland's Maunga Whau Volcano warpbreaks The Number of Breaks in Yarn during Weaving women Average Heights and Weights for American Women
Example
> ls("package:datasets")
Output
[1] "ability.cov" "airmiles" "AirPassengers" [4] "airquality" "anscombe" "attenu" [7] "attitude" "austres" "beaver1" [10] "beaver2" "BJsales" "BJsales.lead" [13] "BOD" "cars" "ChickWeight" [16] "chickwts" "co2" "CO2" [19] "crimtab" "discoveries" "DNase" [22] "esoph" "euro" "euro.cross" [25] "eurodist" "EuStockMarkets" "faithful" [28] "fdeaths" "Formaldehyde" "freeny" [31] "freeny.x" "freeny.y" "HairEyeColor" [34] "Harman23.cor" "Harman74.cor" "Indometh" [37] "infert" "InsectSprays" "iris" [40] "iris3" "islands" "JohnsonJohnson" [43] "LakeHuron" "ldeaths" "lh" [46] "LifeCycleSavings" "Loblolly" "longley" [49] "lynx" "mdeaths" "morley" [52] "mtcars" "nhtemp" "Nile" [55] "nottem" "npk" "occupationalStatus" [58] "Orange" "OrchardSprays" "PlantGrowth" [61] "precip" "presidents" "pressure" [64] "Puromycin" "quakes" "randu" [67] "rivers" "rock" "Seatbelts" [70] "sleep" "stack.loss" "stack.x" [73] "stackloss" "state.abb" "state.area" [76] "state.center" "state.division" "state.name" [79] "state.region" "state.x77" "sunspot.month" [82] "sunspot.year" "sunspots" "swiss" [85] "Theoph" "Titanic" "ToothGrowth" [88] "treering" "trees" "UCBAdmissions" [91] "UKDriverDeaths" "UKgas" "USAccDeaths" [94] "USArrests" "UScitiesD" "USJudgeRatings" [97] "USPersonalExpenditure" "uspop" "VADeaths" [100] "volcano" "warpbreaks" "women" [103] "WorldPhones" "WWWusage"
To view the data sets in a package we need to load the package and then use data(). In this way, we will find the list of the data sets available in a package at the bottom of the window that shows all the data sets in base R.
Example
> library(ggplot2) > data()
Output
Data sets in package ‘ggplot2’: diamonds Prices of 50,000 round cut diamonds economics US economic time series economics_long US economic time series faithfuld 2d density estimate of Old Faithful data luv_colours 'colors()' in Luv space midwest Midwest demographics mpg Fuel economy data from 1999 and 2008 for 38 popular models of car msleep An updated and expanded version of the mammals sleep dataset presidential Terms of 11 presidents from Eisenhower to Obama seals Vector field of seal movements txhousing Housing sales in TX
Now we can use any data set of ggplot2 package, for example viewing the top rows of msleep data −
Example
> head(msleep) # A tibble: 6 x 11
Output
name genus vore order conservation sleep_total sleep_rem sleep_cycle awake <chr> <chr> <chr> <chr> <chr> <dbl> <dbl> <dbl> <dbl> 1 Chee~ Acin~ carni Carn~ lc 12.1 NA NA 11.9 2 Owl ~ Aotus omni Prim~ <NA> 17 1.8 NA 7 3 Moun~ Aplo~ herbi Rode~ nt 14.4 2.4 NA 9.6 4 Grea~ Blar~ omni Sori~ lc 14.9 2.3 0.133 9.1 5 Cow Bos herbi Arti~ domesticated 4 0.7 0.667 20 6 Thre~ Brad~ herbi Pilo~ <NA> 14.4 2.2 0.767 9.6 # ... with 2 more variables: brainwt <dbl>, bodywt <dbl>