On Feb 6, 2012, at 2:22 PM, Abhishek Pratap wrote:

Hey Guys

I want to divide(numerically) all the columns of a data frame by
different numbers. Here is what I am  doing but getting a weird error.
The values in each column are not getting divided by the corresponding
value in the denominator vector instead by the alternative values. I
am sure I am messing up something.

Appreciate your help
-Abhi

head(counts)
              WT_CON WT_RB MU_CON MU_RB
row1       839   180    477   187


head(counts/c(2,3,4,5))
              WT_CON    WT_RB    MU_CON    MU_RB
row1      419.50000  45.0000  238.5000  46.7500

The argument recycling is going to be done on a column basis. You apaear to expect it to be done on a row basis. For that you need apply

Probably:

t( apply(counts, 1, "/", c(2,3,4,5)) )


But untested in absence of example.

---
David Winsemius, MD
West Hartford, CT

______________________________________________
R-help@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.

Reply via email to