Home > database >  How to set a reference row and let other rows to divide its values?
How to set a reference row and let other rows to divide its values?

Time:08-04

Here is a big data frame with different cells and their mRNA expression data:

A Gene 1 Gene 2 Gene 3 Gene 4
Cell 1 9 12 24 42 30
Cell 2 3 6 12 21 15
Cell 3 6 42 48 84 45

Now I want the second column to be the standard and get this:

A Gene 1 Gene 2 Gene 3 Gene 4
Cell 1 3 2 2 2 2
Cell 2 1 1 1 1 1
Cell 3 2 7 4 4 3

CodePudding user response:

I think you can try rep like below

df/df[rep(2,nrow(df)),]

CodePudding user response:

Here is one possible way to solve your problem (assuming that your data is named df):

df[] = Map("/", df, df[2,])
  • Related