Last data update: 2014.03.03

R: bydf
bydfR Documentation

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)

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.

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.

Author(s)

Andrea Franceschini

Examples

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

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(scsR)
Error in library(scsR) : there is no package called 'scsR'
Execution halted