3 Scalar, Dataframe
3 Scalar, Dataframe
• DataFrames in R are generic data objects which are used to store the tabular data.
• Data frame is a two dimensional data structure in R.
• DataFrame is made up of three principal components, the data, rows, and columns.
• A data frame is a special type of list where every element of the list has same
length
• i.e. data frame is a “rectangular” list
• create a new data frame with data.frame() function.
• Find the number of rows and columns with nrow(dat) and ncol(dat), respectively.
• additional attribute: rownames()
• all columns in a data frame are of same type, data frame can be
converted to a matrix with data.matrix() or as.matrix().
• Also created by read.csv() and read.table()
• Data frame is a two dimensional data structure in R.
• A data frame is being used for storing data tables
• dat <- data.frame(id = letters[1:10], x = 1:10, y = 11:20)
• is.list(dat)
• class(dat)
• dat[1, 3]
• As data frames are also lists, it is possible to refer to columns using
the list notation, i.e. either double square brackets [[ ]]or a $.
• dat[["y"]]
• dat$y
USEFUL DATA FRAME FUNCTIONS
emp.data
summary(emp.data)
EXTRACT DATA FROM DATA FRAME
# Extract 3rd and 5th row with 2nd and 4th column.