Re: [R] Summarize data for MCA (FactoMineR)

From: Nelson Castillo <nelsoneci_at_gmail.com>
Date: Fri, 02 May 2008 20:00:37 -0500

On Sun, Apr 27, 2008 at 10:10 AM, David Winsemius <dwinsemius_at_comcast.net> wrote:
> "Nelson Castillo" <nelsoneci_at_gmail.com> wrote in
> news:2accc2ff0804251655o32686b99j73cf7df37243d08f@mail.gmail.com:

(cut)

> > That is, from:
> >
> >> x
> > weight var1 var2
> > 1 1 A B
> > 2 1 A B
> > 3 2 A B
> > 4 1 A B
> > 5 2 C D
> >
> > to:
> >
> >> y
> > weihgt var1 var2
> > 1 5 A B
> > 2 2 C D
> >

>

> Does this suffice?
>

> s.wt <- with(x,
> aggregate(weight, by=list(var1=var1,var2=var2), sum)
> )
> #> s.wt
> # var1 var2 x
> #1 A B 5
> #2 C D 2
>

> #then fix names
> names(s.wt)[3] <- "weight"
>

> #> s.wt
> # var1 var2 weight
> #1 A B 5
> #2 C D 2
That was exactly what I needed :-) Thanks a lot. I tried to make the list that you have to pass as "by" from colnames(edom)[2:14] : [1] "VB21" "VB17_NEV" "VB17_LAV" "VB17_EQS" "VB17_CAL" "VB17_DEL"
 [7] "VB17_LIC" "VB17_HEL" "VB17_AIR" "VB17_VEN" "VB17_TVC" "VB17_PC" [13] "VB17_HMI" But I couldn't do it. So, I did the list by hand.

edom2 = with(edom,aggregate(FACT_EXP_CAL_H, by=list(Income=VB21,VB17_NEV=VB17_NEV, VB17_LAV=VB17_LAV,

VB17_EQS=VB17_EQS, VB17_CAL=VB17_CAL, VB17_DEL=VB17_DEL,
VB17_LIC=VB17_LIC, VB17_HEL=VB17_HEL, VB17_AIR=VB17_AIR,
VB17_VEN=VB17_VEN, VB17_TVC=VB17_TVC, VB17_PC=VB17_PC,
VB17_HMI=VB17_HMI), sum))

> nrow(edom2)

[1] 9817

And the row count matches what I did before with Perl :-)

> I believe that the reshape or reShape packages could do this in one
> step.

I skimmed over the paper and reshape seems to be very powerful. I didn't know how to
use it in this case but I guess I'll get back to the paper some other time.

Regards,
Nelson.-

-- 
http://arhuaco.org

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Sat 03 May 2008 - 01:05:13 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 03 May 2008 - 19:30:37 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive