[R] Urgent Help needed

Weiwei Shi helprhelp at gmail.com
Thu Aug 16 19:27:11 CEST 2007


try this:

t0 = read.table("datatest.txt", header=T)
X.mean = ave(t0[,1], as.factor(t0[,3]))

you do the rest of Y.mean and make them into a data.fame or whatever.

HTH,

Weiwei

On 8/16/07, AbouEl-Makarim Aboueissa <aaboueissa at usm.maine.edu> 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: aaboueissa at usm.maine.edu
>           aboueiss at yahoo.com
> Office: 301C Payson Smith
>
>
> ______________________________________________
> R-help at 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.
>
>
>


-- 
Weiwei Shi, Ph.D
Research Scientist
GeneGO, Inc.

"Did you always know?"
"No, I did not. But I believed..."
---Matrix III



More information about the R-help mailing list