简体   繁体   中英

Inversed rescaling on R dataframe

I am currently using R to assign mutation significance values to proteins in yeast.

I have a data frame that looks like this:

             Genes q_values
1             HNT1 4.836462e-01
2            EMP47 6.792469e-01
3             QDR2 6.357284e-01
4             TMS1 9.781394e-01
5             TMS1 8.672664e-01
...

However, on occasion there will be a q_value significantly lower than the others:

...
35            HHF1 5.565396e-01
36            RGA2 2.323061e-12
37           CDC24 8.174687e-01
...

# Notice how value for row 36 is very low

I want to rescale these q_values onto a 1-10000 scale. However, I need the highest original q_value (ie ~9.85e-01) to be the lowest on the new scale (ei a value of 1). Inversely, the lowest original q_value (ie ~1.36e-13) needs to be the highest on the new scale (ei a value of 10000).

I have tried making a variation of the equation proposed here: https://stats.stackexchange.com/questions/25894/changing-the-scale-of-a-variable-to-0-100 . However I did not manage to get the results I am looking far.

What would be the best way to go about doing this?

Maybe you can try the code below for rescaling the q values

within(df, rescaled_q_values <- 1e5*(max(new_q_values)-new_q_values)/diff(range(new_q_values)))

which gives

   new_yeast_genes new_q_values rescaled_q_values
1             HNT1 4.836462e-01          50554.47
2            EMP47 6.792469e-01          30557.25
3             QDR2 6.357284e-01          35006.36
4             TMS1 9.781394e-01              0.00
5             TMS1 8.672664e-01          11335.09
35            HHF1 5.565396e-01          43102.22
36            RGA2 2.323061e-12         100000.00
37           CDC24 8.174687e-01          16426.16

Data

df <- structure(list(new_yeast_genes = c("HNT1", "EMP47", "QDR2", "TMS1",
"TMS1", "HHF1", "RGA2", "CDC24"), new_q_values = c(0.4836462, 
0.6792469, 0.6357284, 0.9781394, 0.8672664, 0.5565396, 2.323061e-12,
0.8174687)), class = "data.frame", row.names = c("1", "2", "3",
"4", "5", "35", "36", "37"))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM