R Built-in Data Sets - Easy Guides - Wiki (2024)

  • Home
  • Explorer
    • Preleminary tasks
    • List of pre-loaded data
    • Loading a built-in R data
    • Most used R built-in data sets
      • mtcars: Motor Trend Car Road Tests
      • iris
      • ToothGrowth
      • PlantGrowth
      • USArrests
    • Summary
    • Related articles
    • Infos


    R comes with several built-in data sets, which are generally used as demo data for playing with R functions.


    In this article, we’ll first describe how load and use R built-in data sets. Next, we’ll describe some of the most used R demo data sets: mtcars, iris, ToothGrowth, PlantGrowth and USArrests.

    Launch RStudio as described here: Running RStudio and setting up your working directory

    To see the list of pre-loaded data, type the function data():

    data()

    The output is as follow:

    R Built-in Data Sets - Easy Guides - Wiki (1)

    Load and print mtcars data as follow:

    # Loadingdata(mtcars)# Print the first 6 rowshead(mtcars, 6)
     mpg cyl disp hp drat wt qsec vs am gear carbMazda RX4 21.0 6 160 110 3.90 2.620 16.46 0 1 4 4Mazda RX4 Wag 21.0 6 160 110 3.90 2.875 17.02 0 1 4 4Datsun 710 22.8 4 108 93 3.85 2.320 18.61 1 1 4 1Hornet 4 Drive 21.4 6 258 110 3.08 3.215 19.44 1 0 3 1Hornet Sportabout 18.7 8 360 175 3.15 3.440 17.02 0 0 3 2Valiant 18.1 6 225 105 2.76 3.460 20.22 1 0 3 1

    If you want learn more about mtcars data sets, type this:

    ?mtcars

    mtcars: Motor Trend Car Road Tests

    The data was extracted from the 1974 Motor Trend US magazine, and comprises fuel consumption and 10 aspects of automobile design and performance for 32 automobiles (1973–74 models)

    • View the content of mtcars data set:
    # 1. Loading data("mtcars")# 2. Printhead(mtcars)
    • It contains 32 observations and 11 variables:
    # Number of rows (observations)nrow(mtcars)
    [1] 32
    # Number of columns (variables)ncol(mtcars)
    [1] 11
    • Description of variables:
    1. mpg: Miles/(US) gallon
    2. cyl: Number of cylinders
    3. disp: Displacement (cu.in.)
    4. hp: Gross horsepower
    5. drat: Rear axle ratio
    6. wt: Weight (1000 lbs)
    7. qsec: 1/4 mile time
    8. vs: V/S
    9. am: Transmission (0 = automatic, 1 = manual)
    10. gear: Number of forward gears
    11. carb: Number of carburetors

    If you want to learn more about mtcars, type this:

    ?mtcars

    iris

    iris data set gives the measurements in centimeters of the variables sepal length, sepal width, petal length and petal width, respectively, for 50 flowers from each of 3 species of iris. The species are Iris setosa, versicolor, and virginica.

    data("iris")head(iris)
     Sepal.Length Sepal.Width Petal.Length Petal.Width Species1 5.1 3.5 1.4 0.2 setosa2 4.9 3.0 1.4 0.2 setosa3 4.7 3.2 1.3 0.2 setosa4 4.6 3.1 1.5 0.2 setosa5 5.0 3.6 1.4 0.2 setosa6 5.4 3.9 1.7 0.4 setosa

    ToothGrowth

    ToothGrowth data set contains the result from an experiment studying the effect of vitamin C on tooth growth in 60 Guinea pigs. Each animal received one of three dose levels of vitamin C (0.5, 1, and 2 mg/day) by one of two delivery methods, (orange juice or ascorbic acid (a form of vitamin C and coded as VC).

    data("ToothGrowth") head(ToothGrowth)
     len supp dose1 4.2 VC 0.52 11.5 VC 0.53 7.3 VC 0.54 5.8 VC 0.55 6.4 VC 0.56 10.0 VC 0.5
    1. len: Tooth length
    2. supp: Supplement type (VC or OJ).
    3. dose: numeric Dose in milligrams/day

    PlantGrowth

    Results obtained from an experiment to compare yields (as measured by dried weight of plants) obtained under a control and two different treatment condition.

    data("PlantGrowth") head(PlantGrowth)
     weight group1 4.17 ctrl2 5.58 ctrl3 5.18 ctrl4 6.11 ctrl5 4.50 ctrl6 4.61 ctrl

    USArrests

    This data set contains statistics about violent crime rates by us state.

    data("USArrests") head(USArrests)
     Murder Assault UrbanPop RapeAlabama 13.2 236 58 21.2Alaska 10.0 263 48 44.5Arizona 8.1 294 80 31.0Arkansas 8.8 190 50 19.5California 9.0 276 91 40.6Colorado 7.9 204 78 38.7
    1. Murder: Murder arrests (per 100,000)
    2. Assault: Assault arrests (per 100,000)
    3. UrbanPop: Percent urban population
    4. Rape: Rape arrests (per 100,000)

    • Load a built-in R data set: data(“dataset_name”)

    • Inspect the data set: head(dataset_name)
    • Previous chapters
      • What’is R and why learning R?
      • Installing R and RStudio
      • Running RStudio and setting up your working directory
      • R programming basics
      • Getting help with functions in R programming
      • Installing and using R packages
    • Next chapters
      • Importing data into R
      • Exporting data from R

    This analysis has been performed using R (ver. 3.2.3).


    Enjoyed this article? I’d be very grateful if you’d help it spread by emailing it to a friend, or sharing it on Twitter, Facebook or Linked In.

    Show me some love with the like buttons below... Thank you and please don't forget to share and comment below!!

    Avez vous aimé cet article? Je vous serais très reconnaissant si vous aidiez à sa diffusion en l'envoyant par courriel à un ami ou en le partageant sur Twitter, Facebook ou Linked In.

    Montrez-moi un peu d'amour avec les like ci-dessous ... Merci et n'oubliez pas, s'il vous plaît, de partager et de commenter ci-dessous!



    Recommended for You!


    Machine Learning Essentials: Practical Guide in R
    Practical Guide to Cluster Analysis in R
    Practical Guide to Principal Component Methods in R
    R Graphics Essentials for Great Data Visualization
    Network Analysis and Visualization in R
    More books on R and data science

    Recommended for you

    This section contains best data science and self-development resources to help you on your path.

    Coursera - Online Courses and Specialization

    Data science

    Popular Courses Launched in 2020

    Trending Courses

    Books - Data Science

    Our Books

    Others



    Want to Learn More on R Programming and Data Science?

    Follow us by Email

    On Social Networks:

    Get involved :
    Click to follow us on Facebook and Google+ :
    Comment this article by clicking on "Discussion" button (top-right position of this page)

    R Built-in Data Sets - Easy Guides - Wiki (2024)

    References

    Top Articles
    Latest Posts
    Article information

    Author: Kareem Mueller DO

    Last Updated:

    Views: 5712

    Rating: 4.6 / 5 (66 voted)

    Reviews: 89% of readers found this page helpful

    Author information

    Name: Kareem Mueller DO

    Birthday: 1997-01-04

    Address: Apt. 156 12935 Runolfsdottir Mission, Greenfort, MN 74384-6749

    Phone: +16704982844747

    Job: Corporate Administration Planner

    Hobby: Mountain biking, Jewelry making, Stone skipping, Lacemaking, Knife making, Scrapbooking, Letterboxing

    Introduction: My name is Kareem Mueller DO, I am a vivacious, super, thoughtful, excited, handsome, beautiful, combative person who loves writing and wants to share my knowledge and understanding with you.