some common dataframe operations
dataframe_methods
01 Syntax
02 Methods
| Name | Overloads | Summary |
|---|---|---|
| aggregate_eval | 1 | Compute Summary Statistics of Data Subsets Splits the data into subsets, computes summary statistics for each, and returns the result in a convenient form. |
| colSums | 1 | colSums: Form Row and Column Sums and Means Form row and column sums and means for numeric arrays (or data frames). |
| rename | 1 | renames the dataframe object its specific column fields |
| rank_unique | 1 | make rank unique of the element rows inside a dataframe |
| merge | 1 | Merge Two Data Frames Merge two data frames by common columns or row names, or do other versions of database join operations. |
| GetIndex | 1 |
03 Members
Compute Summary Statistics of Data Subsets
Splits the data into subsets, computes summary statistics for each, and returns the result in a convenient form.
| Name | Type | Description |
|---|---|---|
x | Object | an R object. For the formula method a formula, such as y ~ x or cbind(y1, y2) ~ x1 + x2, where the y variables are numeric data to be split into groups according to the grouping x variables (usually factors). |
by | Object | a list of grouping elements, each as long as the variables in the data frame x. The elements are coerced to factors before use. |
FUN | Object | a function to compute the summary statistics which can be applied to all data subsets. |
env | Environment | - |
create data frame
df <- data.frame(team = c('A', 'A', 'A', 'B', 'B', 'B'), position = c('G', 'G', 'F', 'G', 'F', 'F'), points = c(99, 90, 86, 88, 95, 99), assists = c(33, 28, 31, 39, 34, 23), rebounds = c(30, 28, 24, 24, 28, 33));
view data frame
print(df);
team position points assists rebounds
-------------------------------------------------------
<mode> <string> <string> <integer> <integer> <integer>
[1, ] "A" "G" 99 33 30
[2, ] "A" "G" 90 28 28
[3, ] "A" "F" 86 31 24
[4, ] "B" "G" 88 39 24
[5, ] "B" "F" 95 34 28
[6, ] "B" "F" 99 23 33
find mean points by team
aggregate(df$points, by=list(df$team), FUN=mean);
Group x
------------------------
<mode> <string> <double>
A "A" 91.6667
B "B" 94
or
aggregate(df, by = points ~ team, FUN = mean);
Group x
------------------------
<mode> <string> <double>
A "A" 91.6667
B "B" 94
get aggregate function demo
# let f = aggregate(FUN = "mean");
is equalient as the expression mean
f([1,2,3,4,5]); mean([1,2,3,4,5]);
colSums: Form Row and Column Sums and Means
Form row and column sums and means for numeric arrays (or data frames).
| Name | Type | Description |
|---|---|---|
x | dataframe | an array of two or more dimensions, containing numeric, complex, integer or logical values, or a numeric data frame. For .colSums() etc, a numeric, integer or logical matrix (or vector of length m * n). |
env | Environment | - |
renames the dataframe object its specific column fields
| Name | Type | Description |
|---|---|---|
x | dataframe | - |
renames | list | a collection of name mapping lambda, liked: |
env | Environment | - |
this function will returns nothing if the given dataframe object is nothing
make rank unique of the element rows inside a dataframe
| Name | Type | Description |
|---|---|---|
x | dataframe | - |
duplicates | String | the column field name which contains the duplictaed keys for the element rows. |
ranking | Object | the column field name for the ranking score or a numeric vector of the ranking scores for each corresponding element rows. |
env | Environment | - |
a new dataframe object with duplicated rows removed
Merge Two Data Frames
Merge two data frames by common columns or row names, or do other versions of database join operations.
| Name | Type | Description |
|---|---|---|
x | dataframe | data frames, or objects To be coerced To one. |
y | dataframe | data frames, or objects To be coerced To one. |
by | Object | specifications of the columns used for merging. |
env | Object | - |
A data frame. The rows are by default lexicographically sorted on the common columns, but for sort = FALSE are in an unspecified order. The columns are the common columns followed by the remaining columns in x and then those in y. If the matching involved row names, an extra character column called Row.names is added at the left, and in all cases the result has ‘automatic’ row names.
String())| Name | Type | Description |
|---|---|---|
d | dataframe | - |
by | String() | supports multiple column combined as key as here |