- Data frames
- In simple words a data frame is a table
- Rows are called as observations
- Columns are called as variables
- Columns can be different data types
- One column should store only one datatype data
- Create data frame
- Generally we are going to create data frame by importing csv files,relational database,excel ..etc
- First let us see how to create manually
- Structure of the data frame .Notice that above data frame has 3 observations(rows) and 4 variables(columns)
- In create data frame include one more parameter stringsAsFactors = FALSE and observe str(emp.data)
- Summary of data in data frame
- Exercise : create one more dataframe with the name df and with below data
- Extract specific column of a data frame using column name
- Extract the first two rows and then all columns
- Extract the first two columns and then all rows
- Extract specific rows and columns
- Add a column to data frame
- Add row to data frame
- Delete a row from data frame
- Delete column from data frame
- Head(),tail(),dim() functions
- Sort() and order() functions
- The number of data rows in the data frame is given by the nrow() function
- the number of columns of a data frame is given by the ncol() function
- We reference a data frame column with the double square bracket "[[]]" operator.
- For example, to retrieve the ninth column vector of the built-in data set mtcars, we write mtcars[[9]] or mtcars[["am"]] or mtcars$am or mtcars[,"am"]