[R] help with combination problem

David Hugh-Jones davidhughjones at gmail.com
Thu Jun 8 08:50:19 CEST 2006


hi Srinivas

I'm not sure I understand: your example result has 10-9 for mu1 but 1
for mu2, which is not equal to 11-9. I will assume you just got the
numbers wrong. (Also J100 should be J1, no?)

I am also wondering why you want what you say. It doesn't seem very
sensible to mix the results from two data frames like this.

The simplest thing is probably to do the two data frames separately,
then intermix the rows. You can do this with for loops:


for (col1 in paste("T", 1:14, sep="")) {
  for (col2 in paste("N", 1:16, sep="")) result[[paste(col1, "-",
col2, sep="")]] = df1[[col1]] - df1[[col2]]
}

Now repeat for data frame 2 with another data frame, e.g. result2
Then intermix the rows from result and result2. I'll leave you to
figure that bit out.

David



On 07/06/06, Srinivas Iyyer <srini_iyyer_bio at yahoo.com> wrote:
> hello:
>
> I have 3 data.frame objects.
>
> First df object:
> Of dim (149,31). Columns 2:31 are marked as T1..T14
> and N1..N16.
>
> Name     T1    T2    N1   T3   N2  N3  N4  T4
> mu1      10    10    9    10   9   9   8   10
> mu2      11    11    9    11   9   9   9   11
> ...
> muN      12    12    9    11   9   9   8   12
>
>
>
>
> Second df object:
> of Dim (50000,31). Columns 2:31 are maked as T1...T14
> and N1..N16.
>
> Name     T1    T2    N1   T3   N2  N3  N4  T4
> J1       2     3     20   2    22  21  29   3
> J2       4     1     20   3    20  21  22   4
> J3       3     1     33   1    31  31  33   3
> ...
> JX       3     2     20   2    21  22  24   2
>
> The column samples are identical in both first and
> second data frames.
>
> Third df object:
> of Dim (200,2).
>
> V1         V2
> mu1:J1     -11
> mu1:J100   -10.4
> mu2:J31     11.3
> mu2:J2      10.4
> .....       .....
> muN:JX     34.5
>
>
>
> I want to create a combination of Ts and Ns. Where I
> want to subtract value of T-N in all combinations(225
> combinations). Such as
> T1-N1,T1-N2,T1-N3,T1-N4,T1-N5.......T14-N16
>
> The rows should be the row pairs from 3rd dataframe.
>
>
> The final resultant matrix should look like the
> following:
>
>
>      T1-N1  T1-N2  T1-N3  T1-N4  T1-N5.......T14-N16
> mu1   1(10-9) 1(10-9)   1    2      1            1
> J100  -18(2-20) -20   -19  -27    -20          -29
>
> mu2     1     3        2     2      1            1
> J2     -19   -21     -39    -31    -31         -28
>
>
>
> I am a beginner level in R.  I apologise for asking
> such a big question and subsequent help. I am unable
> to go forward as I have no idea as to how to do this.
> Could any one please help me.
> Thanks
> sri
>
> ______________________________________________
> 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
>



More information about the R-help mailing list