-2

Having a dataframe in R, I'd like to divide all rows in a given column by a name-speficied row (here 'ABC') from the same column, and apply these to all the columns using this specific row as the normalizer.

Input:

A   1   1
B   1   2
C   4   4
ABC 2   2
E   2   3

Output:

A   0.5 0.5
B   0.5 1
C   2   2
ABC 1   1
E   1   1.5

Many thanks in advance!

Jaap
  • 81,064
  • 34
  • 182
  • 193
user2904120
  • 416
  • 1
  • 4
  • 18
  • Could you please produce a reproducible example with sample code and the corresponding data extract? You may also consider being more specific in your request, do you want to [split the column](http://stackoverflow.com/q/7069076/1655567) or split *(which in effect would correspond to subsetting )* the rows in the data frame according to column values? – Konrad Feb 03 '16 at 16:40
  • Sorry, uploaded accidentally too early. I only want to divide, always by ABC for each column – user2904120 Feb 03 '16 at 16:46

1 Answers1

2

Another option is

df1[-1] <- df1[-1]/df1[df1$v1=='ABC', -1][col(df1[-1])]
akrun
  • 874,273
  • 37
  • 540
  • 662