[R] How to best divide table by table

Martin Maechler maechler at stat.math.ethz.ch
Mon Oct 30 10:08:31 CET 2006


But *please* do learn from Peter Dalgaard's answer
that this has nothing to do with "table"s 
(Petr, I agree you have "helped" Serguei, but...)

Using vague language is not helpful  in such contexts.
And hence, calling data frames 'tab1' is probably not a good
idea.
{Calling them 'data' is not much better though:

  > fortune("dog")

  Firstly, don't call your matrix 'matrix'. Would you call your dog 'dog'?
  Anyway, it might clash with the function 'matrix'.
     -- Barry Rowlingson
	R-help (October 2004)
}

Martin Maechler

>>>>> "Petr" == Petr Pikal <petr.pikal at precheza.cz>
>>>>>     on Mon, 30 Oct 2006 08:12:57 +0100 writes:

    Petr> Hi Assuming the same order in both tables divide only
    Petr> columns you wont and then add column of names. You
    Petr> need to work with data frame, as working with matrices
    Petr> cannot use mixed types columns.

    Petr> tab1<-data.frame(letters[1:3], 1:3)
    Petr> tab2<-data.frame(letters[1:3], 10)
    Petr> data.frame(tab1[,1],tab1[,-1]/tab2[,-1])
    Petr> tab1...1. tab1....1..tab2....1.  1 a 0.1 2 b 0.2 3 c
    Petr> 0.3

    Petr> How to set appropriate column names you can find in
    Petr> help page ?data.frame
 
    Petr> HTH Petr


    Petr> On 27 Oct 2006 at 18:42, Serguei Kaniovski wrote:

    Petr> Date sent: Fri, 27 Oct 2006 18:42:36 +0200 (CEST)
    Petr> From: Serguei Kaniovski <kaniovsk at wsr.ac.at> To:
    Petr> r-help at stat.math.ethz.ch Organization: WIFO Subject:
    Petr> [R] How to best divide table by table

    >> Hi all,
    >> 
    >> how can I divide two tables of the same dimension so that
    >> all names are preserved, ie do not become NA? I have
    >> "tab1" and "tab2", each having names in the first
    >> column. I want "tab3" with the same names and values
    >> "tab1/tab2".
    >> 
    >> Thanks, Serguei



More information about the R-help mailing list