Database Reference
In-Depth Information
# extract the fourth column of the sales data frame
sales[,4]
# extract the gender column of the sales data frame
sales$gender
# retrieve the first two rows of the data frame
sales[1:2,]
# retrieve the first, third, and fourth columns
sales[,c(1,3,4)]
# retrieve both the cust_id and the sales_total columns
sales[,c("cust_id", "sales_total")]
# retrieve all the records whose gender is female
sales[sales$gender=="F",]
The following R code shows that the class of the sales variable is a data frame.
However, the type of the sales variable is a list. A list is a collection of objects
that can be of various types, including other lists.
class(sales)
"data.frame"
typeof(sales)
"list"
Lists
Lists can contain any type of objects, including other lists. Using the vector v
and the matrix M created in earlier examples, the following R code creates
assortment , a list of different object types.
# build an assorted list of a string, a numeric, a list, a
vector,
# and a matrix
housing <- list("own", "rent")
assortment <- list("football", 7.5, housing, v, M)
assortment
[[1]]
[1] "football"
[[2]]
[1] 7.5
[[3]]
[[3]][[1]]
Search WWH ::




Custom Search