A data frame is a collection of variables which share many of the properties of matrices and lists. More precisely, a data frame is a list of variables of the same length with unique row names. It is given class name ”data.frame”.
Create Data Frame
id=c(1:10)
name=c("emma","well","rich","rahul","sam","shiv","raj","mayur","sush","rock")
salary=c(122,251,824,454,556,767,876,596,395,345)
emp=data.frame(id,name,salary)
print(emp)
When you execute the above code, it produces the following output :
emp$id - is one way to access a variable inside the data frame.
emp$id[1] - access first element of the vector.
emp$id[2:3] - access a subset of elements.
emp$name[c(5,7)] - access elements 5 and 7.
emp$id
emp$id[1]
emp$id[2:5]
emp$name[c(5,7)]
output -
Summary of Data
The statistical summary of the data can retrived by using summary() function.
id=c(1:10)
name=c("emma","well","rich","rahul","sam","shiv","raj","mayur","sush","rock")
salary=c(122,251,824,454,556,767,876,596,395,345)
emp=data.frame(id,name,salary)
summary(emp)
When you execute the above code, it produces the following output :