基于一列进行标准化的 R 函数?

标签 r normalization standardized

是否可以根据最后一列(样本)样本 = 已测序基因组的数量在 R 中标准化此表。所以我想得到所有条件下所有基因的标准化分布。

我的数据的简化示例:

enter image description here

我尝试过:

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/

相关文章:

r - Z 标准化使得 PC1 和 PC2 在此 PCA 分析中完全相同 : Why?

r - 每天将 "data.frame"传输到 R 中的 "ts"

search - 如何在Elasticsearch中对朝鲜语单词使用前缀查询?

machine-learning - "batch normalizaiton"是什么?为什么使用它?它如何影响预测?

mysql搜索和索引性能

python - 数据标准化 vs 规范化 vs Robust Scaler

r - 如何绘制连接点的矩形网格

r - 以优化的方式将现有二维点移动到新生成的二维点

r - data.table 中的 .internal.selfref 无效

r - R 中 MuMIn 包的标准化