person_mean: Calculates the mean of variables at the person level

Description Usage Arguments Details

Description

This is a simple function that returns a dataframe in which the person-level mean of any input variables has been calculated. Output variables will be named 'input_variable_mean'

Usage

1
person_mean(data, variables, person_id)

Arguments

data

The input dataset

variables

A character vector of input variables e.g. c('negemo', 'posemo').

person_id

The grouping variable to calculate your mean at - this should be your person id variable.

Details

Technically, it will calculate the mean at any level, but I have used simple dplyr to set the output to 'original_variable_name_mean'. It is technically possible to write functions that flexible assign the output name so a simple 'esm_mean' function could be created to work at any level and allow the user to specify output variable names. But I made a design decision to be moderately constrictive here for ease of use and also to ensure that variables are consistently named coming out of these functions.


seanchrismurphy/emacalc documentation built on May 12, 2019, 2:03 p.m.