Skip to content

meaning of formula in aggregate function

3 messages · Den, Peter Ehlers

Den
#
Dear Dennis
Thank you very much for your comprehensive reply and for time you've
spent dealing with my e-mail.
Your kindly explanation made things clearer for me. 
After your explanation it looks simple.
lapply with chosen options takes small part of cycle<n> with same id
(eg. df[df$id==3,"cycle2"] and makes from it just a bunch of
characters. 
The only thing I still don't get is why how this code get rid out of
NAs, but this is rather minor technical issue. Main question for me was
in formula. You helped me indeed.
Thank you again
Have a nice day
Denis
? ???, 22/01/2011 ? 17:55 -0800, Dennis Murphy ????:
#
Den wrote:
Okay, now I see what you're asking regarding the NAs.
I should have realized it before. Anyway, the answer
is in the function sort(). Have a look at its help
page and note what sort does when 'na.last=NA', the
default. You'll see where the NAs went.

Peter Ehlers
Den
#
Dear Peter
Thank you
Lo and behold
Now I've got it

In code
aggregate(.~ id, lapply(df, as.character), FUN =
function(x)paste(sort(x), collapse = ''), na.action = na.pass)

there are no contradictions with NAs.

na.action = na.pass is applied to aggregate where default is na.omit.
And afterwards those NAs are removed by sort command.

It is a lot easier for me to deal with data when I know what I am doing.
Thank you again for help. Sorry for annoying naive questions. 

With best regards
Denis Kazakiewicz
Belarus 




 ???, 23/01/2011 ? 05:38 -0800, P Ehlers ????: