Re: [R] Dividing Two Dataframes

From: ONKELINX, Thierry <>
Date: Wed, 14 May 2008 16:03:01 +0200

Dear Bert,

Another option is to replicate SDF2 so the number of rows matches with those of SDF1.

SDF1 <- data.frame(matrix(rnorm(144 * 2), nrow = 144)) SDF2 <- data.frame(matrix(rnorm(12 * 2), nrow = 12)) SDF1 / SDF2 #yields the error

SDF2a <-, rep(list(SDF2), nrow(SDF1) / nrow(SDF2))) SDF1 / SDF2a #this works

HTH, Thierry

ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4
9500 Geraardsbergen
tel. + 32 54/436 185

To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of.
~ Sir Ronald Aylmer Fisher

The plural of anecdote is not data.
~ Roger Brinner

The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data.
~ John Tukey

-----Oorspronkelijk bericht-----
Van: [] Namens Bert Jacobs Verzonden: woensdag 14 mei 2008 15:43
Aan: 'Henrique Dallazuanna'
Onderwerp: 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)

Is it easy to adapt your formula to get this result?



From: Henrique Dallazuanna [] Sent: 14 May 2008 13:34
To: Bert Jacobs
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 <> wrote:


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.


       [[alternative HTML version deleted]] mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code.
Henrique Dallazuanna
25° 25' 40" S 49° 16' 22" O 

	[[alternative HTML version deleted]]

______________________________________________ mailing list
PLEASE do read the posting guide
and provide commented, minimal, self-contained, reproducible code.
Received on Wed 14 May 2008 - 16:56:23 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 14 May 2008 - 18:30:36 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive