Re: [R] How to best divide table by table

From: Petr Pikal <petr.pikal_at_precheza.cz>
Date: Mon 30 Oct 2006 - 07:12:57 GMT


Hi

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

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

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

HTH
Petr

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

Date sent:      	Fri, 27 Oct 2006 18:42:36 +0200 (CEST)
From:           	Serguei Kaniovski <kaniovsk@wsr.ac.at>
To:             	r-help@stat.math.ethz.ch
Organization:   	WIFO
Subject:        	[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
>
> ______________________________________________
> 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.

Petr Pikal
petr.pikal@precheza.cz



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. Received on Mon Oct 30 18:17:24 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Mon 30 Oct 2006 - 09:30:14 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.