Using data.frame function, create a dataframe that contains names of people, age, weight and sex of those people and check whether mtcars is a data frame or not.

698    Asked by shukhdevsingh in Data Science , Asked on Nov 2, 2019
Answered by shukhdev singh

A data frame is a structure having 2 dimensions which contains data in the form or rows and columns.It is like a spreadsheet or dictionaries of series. To create a dataframe in R, we use data.frame function which combines all the input data and creates a dataframe.

Given in the question let us create the data of few people that contains names, age, weight and sex.


Name <- c("Sam","Frank","Amy")

Age <- c(22,25,26)

Weight <- c(150,165,120)

Sex <- c("M", "M", "F")

df <- data.frame (row.names = Name, Age, Weight, Sex)

df


Now to check whether mtcars is a data frame or not, we can check as the following.

is.data.frame(mtcars)

Output: True


Mtcars is a built in dataset in R which contains data of several cars of many companies with their features such as MPG, HP, vol, etc. Let us see the head of the data mtcars





Your Answer

Interviews

Parent Categories