Skip to content
Back to formatted view

Raw Message

Message-ID: <79975826-774A-4072-83D4-7634C48F5729@googlemail.com>
Date: 2012-09-25T21:32:05Z
From: Martin Batholdy
Subject: mean-aggregate – but use unique for factor variables

Hi,

I have a data.frame which I want to aggregate.
There are some grouping variables and some continuous variables for which I would like to have the mean.

However there are also some factor-variables in the data-frame that are not grouping variables and I actually would like to aggregate these variables with the unique() function.

Is that possible with the standard aggregate-function?

If I use it like this:

aggregate(data, by=list(data$grouping1, data$grouping2), FUN=mean)

I get vectors of NAs for the other factor-variables in the data.frame.
But I actually want the unique value ?

Is that possible?


thanks!