Tutorial by Examples

A data.frame is a special kind of list: it is rectangular. Each element (column) of the list has same length, and where each row has a "row name". Each column has its own class, but the class of one column can be different from the class of another column (unlike a matrix, where all elemen...
Syntax for accessing rows and columns: [, [[, and $ This topic covers the most common syntax to access specific rows and columns of a data frame. These are Like a matrix with single brackets data[rows, columns] Using row and column numbers Using column (and row) names Like a list: Wi...
Some convenience functions to manipulate data.frames are subset(), transform(), with() and within(). subset The subset() function allows you to subset a data.frame in a more convenient way (subset also works with other classes): subset(mtcars, subset = cyl == 6, select = c("mpg", "...
Data frames are likely the data structure you will used most in your analyses. A data frame is a special kind of list that stores same-length vectors of different classes. You create data frames using the data.frame function. The example below shows this by combining a numeric and a character vector...
If you have your data stored in a list and you want to convert this list to a data frame the do.call function is an easy way to achieve this. However, it is important that all list elements have the same length in order to prevent unintended recycling of values. dataList <- list(1:3,4:6,7:9) ...
A common task is to convert all columns of a data.frame to character class for ease of manipulation, such as in the cases of sending data.frames to a RDBMS or merging data.frames containing factors where levels may differ between input data.frames. The best time to do this is when the data is read ...
Built in functions can subset rows with columns that meet conditions. df <- data.frame(item = c(1:10), price_Elasticity = c(-0.57667, 0.03205, -0.04904, 0.10342, 0.04029, 0.0742, 0.1669, 0.0313, 0.22204, 0.06158), total...

Page 1 of 1