是否可以根据最后一列(样本)样本 = 已测序基因组的数量在 R 中标准化此表。所以我想得到所有条件下所有基因的标准化分布。
我的数据的简化示例:
我尝试过:
dat1 <- read.table(text = " gene1 gene2 gene3 samples
condition1 1 1 8 120
condition2 18 4 1 118
condition3 0 0 1 75
condition4 32 1 1 130", header = TRUE)
dat1<-normalize(dat1, method = "standardize", range = c(0, 1), margin = 1L, on.constant = "quiet")
但是结果包含负值,我不确定这种方法有多大用处。 谁能建议我应该如何标准化我的数据......以获得有意义的结果。
非常感谢,如果这是一个愚蠢的问题,我们深表歉意。
最佳答案
使用您的数据,首先编写一个最小最大函数:
minmax = function(x){ (x-min(x))/(max(x)-min(x))}
然后遍历列:
norm = data.frame(lapply(dat1[,1:3],function(i) minmax(i/dat1$samples)))
看起来像这样,我希望它是正确的:
gene1 gene2 gene3
1 0.03385417 0.2458333 1.00000000
2 0.61970339 1.0000000 0.01326455
3 0.00000000 0.0000000 0.09565217
4 1.00000000 0.2269231 0.00000000
关于基于一列进行标准化的 R 函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64873299/