I am creating variables representing intraindividual means and standard
deviations for longitudinal data with the following code:

data$TraitHAPPYmean <- with(data, ave(Happy, ID, FUN=function(x) mean(x,
na.rm=TRUE) )  )

&

data$TraitHAPPYsd <- with(data, ave(Happy, ID, FUN=function(x) sd(x,
na.rm=TRUE) )  )

where 'Happy' is the variable that was collected at multiple timepoint,
'ID' is the grouping variable, and TraitHAPPYMean & SD are the new
variables. I'd like to also create a variable that just returns the # of
cases for each grouping variable (ID). For example, some IDs might have 10
cases of Happy that went into the intraindividual mean, while others have
only 5.

I realize that this is probably a very basic question, but I just cannot
figure it out! Thanks.

	[[alternative HTML version deleted]]

