Learn R Programming

scsR (version 1.8.0)

bydf: bydf

Description

apply a function to a group of rows in the input data frame (similar to the sql group by statememnt).

Usage

bydf(df, groupColName, valColName, fun, newColName="temp_by_col_name")
bydfa(df, groupColName, valColName, fun, newColName="temp_by_col_name")

Arguments

df
input data frame
groupColName
name of the column to be used for grouping the rows (character vector)
valColName
name of the column containing the values to be inserted in the function (character vector)
fun
function to be applied (function)
newColName
name of the colum that contains the result of the function (character vector)

Value

bydf: data frame with the function applied to the grouping bydfa: input data frame with an additional column with the results of the function applied to the grouping.

Details

The methods currently depend on the type of to:
bydf
apply a function to a group of rows in the input data frame (similar to the sql group by statememnt). Put the results of this function in a new data frame that is returned as output.

bydfa
apply a function to a group of rows in the input data frame (similar to the sql group by statememnt). return the same data frame with an additional column with the results of the function.

Examples

Run this code
	data(uuk_screen)
	screen=add_seed(uuk_screen[1:1000,])
	screen_sd = bydf(screen, groupColName="seed7", "score", sd, "sd")

Run the code above in your browser using DataLab