Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Data Visualization
  • Statistics in R
  • Machine Learning in R
  • Data Science in R
  • Packages in R
  • Data Types
  • String
  • Array
  • Vector
  • Lists
  • Matrices
  • Oops in R
Open In App
Next Article:
Display the internal Structure of an Object in R Programming - str() Function
Next article icon

Display the internal Structure of an Object in R Programming - str() Function

Last Updated : 05 Jun, 2020
Comments
Improve
Suggest changes
Like Article
Like
Report
str() function in R Language is used for compactly displaying the internal structure of a R object. It can display even the internal structure of large lists which are nested. It provides one liner output for the basic R objects letting the user know about the object and its constituents. It can be used as an alternative to summary() but str() is more compact than summary(). It gives information about the rows(observations) and columns(variables) along with additional information like the names of the columns, class of each columns followed by few of the initial observations of each of the columns.
Syntax: str(object, ...) Parameter: object: Any R object about which information is required.
Example 1: Python3
# R program to display  # structure of a list  # Creating a list gfg <- list(2, 4, 5, 6, 7, 9, 13, 15, 3, 1)  # Calling str() function str(gfg) 
Output:
List of 10   $ : num 2   $ : num 4   $ : num 5   $ : num 6   $ : num 7   $ : num 9   $ : num 13   $ : num 15   $ : num 3   $ : num 1  
Here, we can observe the output which is a description of the object gfg. It mentions that it is a list having 10 components. In the following rows, it displays each one of them along with their class i.e. numeric in this case. Example 2: Python3
# R program to display structure  # of a pre-defined dataset  # Importing Library library(datasets)  # Importing dataset head(airquality)  # Calling str() function str(airquality) 
Here, head(airquality) will display the first few rows of the data frame. After executing, the following output will be displayed. Output :
    Ozone Solar.R Wind Temp Month Day  1    41     190  7.4   67     5   1  2    36     118  8.0   72     5   2  3    12     149 12.6   74     5   3  4    18     313 11.5   62     5   4  5    NA      NA 14.3   56     5   5  6    28      NA 14.9   66     5   6  'data.frame':    153 obs. of  6 variables:   $ Ozone  : int  41 36 12 18 NA 28 23 19 8 NA ...   $ Solar.R: int  190 118 149 313 NA NA 299 99 19 194 ...   $ Wind   : num  7.4 8 12.6 11.5 14.3 14.9 8.6 13.8 20.1 8.6 ...   $ Temp   : int  67 72 74 62 56 66 65 59 61 69 ...   $ Month  : int  5 5 5 5 5 5 5 5 5 5 ...   $ Day    : int  1 2 3 4 5 6 7 8 9 10 ...  
It provides us the information that the dataset airquality is a data frame with 153 observations(rows) of 6 variables(columns). Then it tells us about each variable one by one as follows, the first column with name Ozone is of type integer followed by few of its values and the second column is named Solar.R which is also of the integer type followed by few of its contents and so on. str() will be really useful when we are unsure about the contents of an object as it will help us take a quick preview of the contents and structure of the object. This will also help in revealing issues in the naming of the columns, class of the content, etc, if any exist.

Next Article
Display the internal Structure of an Object in R Programming - str() Function

A

anupama0699
Improve
Article Tags :
  • R Language
  • R DataFrame-Function
  • R Vector-Function
  • R Object-Function
  • R Matrix-Function

Similar Reads

    Get or Set the Type of an Object in R Programming - mode() Function
    mode() function in R Language is used to get or set the type or storage mode of an object. Syntax: mode(x) mode(x) <- value Here "value" is the desired mode or ‘storage mode’ (type) of the object Parameters: x: R object Example 1: Python3 # R program to illustrate # mode function # Init
    1 min read
    Get or Set the Structure of a Vector in R Programming - structure() Function
    structure() function in R Language is used to get or set the structure of a vector by changing its dimensions. Syntax: structure(vec, dim) Parameters: vec: Vector dim: New Dimensions Example 1: Python3 1== # R program to get # the structure of a Vector # Creating a Vector # of Numbers x1 <- c(1:1
    1 min read
    Convert an Object into a Vector in R Programming - as.vector() Function
    as.vector() function in R Language is used to convert an object into a vector. Syntax: as.vector(x) Parameters: x: Object to be converted Example 1: Python3 1== # R program to convert an object to vector # Creating an array x <- array(c(2, 3, 4, 7, 2, 5), c(3, 2)) x # Calling as.vector() Function
    1 min read
    Getting String Representation of the given Date and Time Object in R Programming - strftime() Function
    strftime() function in R Language is used to convert the given date and time objects to their string representation.  Syntax: strftime(time) Parameters: time: specified time object  Example 1:   Python3 # R program to illustrate # strftime function # Specifying a date and time x <- "2020-06-01 16
    1 min read
    Search and Return an Object with the specified name in R Programming - get() Function
    get() function in R Language is used to return an object with the name specified as argument to the function. This is another method of printing values of the objects just like print function. This function can also be used to copy one object to another. Syntax: get(object) Parameters: object: Vecto
    1 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences