将范围从(0到+1)的值转换为R中的负值

问题描述 投票:0回答:1

我对R中数据帧中的值的转换有疑问。我拥有计算的数据,该数据由从(0到0.999)到(1到无穷大)的值组成。我想保留表中的(1到无穷大)值,但是,为了使用公式(-1/[(0 to 0.999)])绘制热图,想将(0到0.999)转换为负值。以下是我的输入和输出数据的示例。请协助我。

Input_Data <- read.csv(file = "./Synthetic_Data_Input.csv",stringsAsFactors = FALSE, row.names = 1)
Output_Data <- read.csv(file = "./Synthetic_Data_Output.csv",stringsAsFactors = FALSE, row.names = 1)

dput(Input_Data)
structure(list(Sample_1 = c(0.942972, 1.00812, 1.10038, 1.19572, 
1.28194, 1.37384, 1.75378, 2.56584, 2.56584), Sample_3 = c(0.517607, 
0.935699, 0.567427, 0.572821, 0.795282, 0.541105, 1.03596, 2.78013, 
0.189337)), class = "data.frame", row.names = c("Gene_4", "Gene_7", 
"Gene_2", "Gene_3", "Gene_6", "Gene_9", "Gene_5", "Gene_8", "Gene_1"
))


dput(Output_Data)
structure(list(Sample_1 = c(-1.060476875, 1.00812, 1.10038, 1.19572, 
1.28194, 1.37384, 1.75378, 2.56584, 2.56584), Sample_3 = c(-1.93196769, 
-1.068719749, -1.762341235, -1.745746053, -1.257415609, -1.848070153, 
1.03596, 2.78013, -5.281587857)), class = "data.frame", row.names = c("Gene_4", 
"Gene_7", "Gene_2", "Gene_3", "Gene_6", "Gene_9", "Gene_5", "Gene_8", 
"Gene_1"))

谢谢,Toufiq

r dataframe data-conversion
1个回答
2
投票

我们只能更改0 to 0.999范围内的值。

inds <- Input_Data <= 0.999
Input_Data[inds] <- -1/Input_Data[inds]

Input_Data
#        Sample_1  Sample_3
#Gene_4 -1.060477 -1.931968
#Gene_7  1.008120 -1.068720
#Gene_2  1.100380 -1.762341
#Gene_3  1.195720 -1.745746
#Gene_6  1.281940 -1.257416
#Gene_9  1.373840 -1.848070
#Gene_5  1.753780  1.035960
#Gene_8  2.565840  2.780130
#Gene_1  2.565840 -5.281588
© www.soinside.com 2019 - 2024. All rights reserved.