Getting the structure of R Data Frame
In R, we can find the structure of our data frame. R provides an in-build function called str() which returns the data with its complete structure. In below example, we have created a frame using a vector of different data type and extracted the structure of it.
Example
# Creating the data frame. emp.data<- data.frame( employee_id = c (1:5), employee_name = c("Shubham","Arpita","Nishka","Gunjan","Sumit"), sal = c(623.3,515.2,611.0,729.0,843.25), starting_date = as.Date(c("2012-01-01", "2013-09-23", "2014-11-15", "2014-05-11", "2015-03-27")), stringsAsFactors = FALSE ) # Printing the structure of data frame. str(emp.data)
Output
'data.frame': 5 obs. of 4 variables:
$ employee_id : int 1 2 3 4 5
$ employee_name: chr "Shubham" "Arpita" "Nishka" "Gunjan" ...
$ sal : num 623 515 611 729 843
$ starting_date: Date, format: "2012-01-01" "2013-09-23" ...