# Re: [R] Dividing Two Dataframes

From: Greg Snow <Greg.Snow_at_imail.org>
Date: Wed, 14 May 2008 07:57:41 -0600

SDF3 <- SDF1/SDF2[ rep(1:12,12), ]

-----Original Message-----
From: "Bert Jacobs" <b.jacobs_at_pandora.be> To: "'Henrique Dallazuanna'" <wwwhsd_at_gmail.com> Cc: "r-help_at_r-project.org" <r-help_at_r-project.org> Sent: 5/14/08 7:41 AM
Subject: Re: [R] Dividing Two Dataframes

Hi Henrique,

I think I understand your formula, but your final result is a 12x160 data.frame, while it should be a 144x160 data.frame

divide rows 1:12 with SDF2 (=12 rows)

divide rows 13:24 with SDF2 (=12 rows)

divide rows 25:36 with SDF2 (=12 rows)

divide rows 133:144 with SDF2 (=12 rows)

Thx,

Bert

From: Henrique Dallazuanna [mailto:wwwhsd_at_gmail.com] Sent: 14 May 2008 13:34
To: Bert Jacobs
Cc: r-help_at_r-project.org
Subject: Re: [R] Dividing Two Dataframes

Try this:

DFS <- lapply(split(seq(1, 144, by = 1), rep(1:12, each = 12)), function(x)SDF1[x,]/SDF2)

On Wed, May 14, 2008 at 5:02 AM, Bert Jacobs <b.jacobs_at_pandora.be> wrote:

Hi,

I have two dataframes one with 144 rows and 160 columns (SDF1) and one with 12 rows and 160 columns (SDF2).

Now I'm trying to divide rows 1:12 with SDF2, rows 13:24 with SDF2, rows 25:36 with SDF 2, .

In S-Plus the following code works fine:

DFS = SDF1[1:144,1:60] / as.vector(SDF2[1:12,1:160])

but in R when I try to implement the formula I get the following error:

"/ only defined for equally-sized data frames"

Can someone help me out on this one. Thx in advance.

Bert

[[alternative HTML version deleted]]

R-help_at_r-project.org 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.
```--
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

[[alternative HTML version deleted]]

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help