Hi, try this:

by(df[,1:2], df$index, FUN=function(x)cor(x[1],x[2]))

-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

On 16/08/07, AbouEl-Makarim Aboueissa <[EMAIL PROTECTED]> wrote:
>
> Thanks all.
>
> it works.
>
> Just one more thing: if you look to this out put,
>
> > by(data1[,2:3], data1[,4], cor)[1]
> $`1`
>             X                            Y
> X   1.0000000            0.4400451
> Y   0.4400451  1.0000000
>
> Q. How I can just pick the value of the correlation 0.4400451 from this
> output and call it sat corxy.
>
>
> Once again thank you all so much for your helps.
>
>
> Abou
>
>
> ==========================
> AbouEl-Makarim Aboueissa, Ph.D.
> Assistant Professor of Statistics
> Department of Mathematics & Statistics
> University of Southern Maine
> 96 Falmouth Street
> P.O. Box 9300
> Portland, ME 04104-9300
>
> Tel: (207) 228-8389
> Email: [EMAIL PROTECTED]
>           [EMAIL PROTECTED]
> Office: 301C Payson Smith
>
> >>> "Henrique Dallazuanna" <[EMAIL PROTECTED]> 8/16/2007 2:05 PM >>>
> For the 2nd item, perhaps:
>
> by(df[,1:2], df$index, FUN=cor)
>
> where df is your data.frame.
>
> --
> Henrique Dallazuanna
> Curitiba-Paraná-Brasil
> 25° 25' 40" S 49° 16' 22" O
>
> On 16/08/07, AbouEl-Makarim Aboueissa <[EMAIL PROTECTED]> wrote:
> >
> > Dear All:
> >
> > Urgent help is needed.
> >
> >
> > I have a data set in matrix format  of three columns: X, Y and index of
> > four groups (1,2,3,4). What I need to do is the following;
> >
> > 1- How I can subtract the sample mean of each group indexed 1,2,3,4 from
> > the
> >      corresponding data values of this group and create new columns say
> > X-sample mean
> >       and Y-sample mean? I tried to use the "tapply" but I have some
> > difficulties to restore the new data
> >
> >
> > 2- How I can use the "tapply" if possible or any other R-function to
> find
> > the correlation
> >      coefficient between the X and Y columns for each group indexed
> > 1,2,3,4.? Could not use the "tapply".
> >
> >
> > I attached part of the data as txt file.
> >
> >
> > Thank you so much for your attention to this matter, and I look forward
> to
> > hear from you soon.
> >
> > Regards,
> >
> > Abou
> >
> >
> > Data:
> > ====
> > x       y       index
> > 15807.24        12.5    4
> > 15752.51        33.5    4
> > 12893.76        01.5    3
> > 8426.88         22.2    3
> > 5706.24         333     3
> > 3982.08         560     2
> > 3642.62         670     2
> > 295.68          124     1
> > 215.40          104     1
> > 195.40          204     1
> > 4240.21         22.4    2
> > 1222.72         45.9    2
> > 1142.26         23.6    2
> > 63.00           90.1    1
> > 1216.00         82.4    2
> > 2769.60         111     2
> > 1790.46         34.7    2
> > 26.10           26.10   1
> > 19676.83        0.99    4
> > 10920.60        203     3
> > 6144.00         46      3
> > 4534.48         4534.48 3
> > 40000.00        65      4
> > 29500.00        56      4
> > 17100.00        77      4
> > 9000.00         435     3
> > 6300.00         84      3
> > 3962.88         334     2
> > 5690.00         653     3
> > 3736.00         233     2
> > 2750.00         22      2
> > 1316.00         345     2
> > 4595.00         4595.00 3
> > 5928.00         45      3
> > 2645.70         0.00    2
> > 2580.24         454     2
> > 6547.34         6547.34 3
> > 1615.68         5       2
> > 194.06          55      1
> > 184.80          6       1
> > 82.94           44      1
> > 16649.00        56      4
> > 4500.00         74      3
> > 1600.00         744     2
> >
> > =================
> >
> >
> >
> > ==========================
> > AbouEl-Makarim Aboueissa, Ph.D.
> > Assistant Professor of Statistics
> > Department of Mathematics & Statistics
> > University of Southern Maine
> > 96 Falmouth Street
> > P.O. Box 9300
> > Portland, ME 04104-9300
> >
> > Tel: (207) 228-8389
> > Email: [EMAIL PROTECTED]
> >           [EMAIL PROTECTED]
> > Office: 301C Payson Smith
> >
> >
> > ______________________________________________
> > R-help@stat.math.ethz.ch 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.
> >
> >
> >
>
>

        [[alternative HTML version deleted]]

______________________________________________
R-help@stat.math.ethz.ch 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.

Reply via email to